Cumulia Illustrator Rendering Engine v1.1.0
A Rendering engine for industrial CAD/CAE model and optimized for greatest performance
 
Loading...
Searching...
No Matches
builder.h
1//##################################################################################################
2//
3// Copyright (c) 2024 Beijing Qiongqi Tech Co.,Ltd. All rights reserved.
4
5// This source code is confidential and proprietary to Beijing Qiongqi Tech Co.,Ltd(The Holder).
6// Any unauthorized use, copying, modification, or distribution of the code is strictly prohibited.
7// Any user shall obtain authorizaition from the Holder before modifying the source code. And the user shall not
8// sublicense, sell, distribute, or transfer the source code, whether in original or modified form, to any third party
9// without the prior written consent of the Holder.
10
11// This copyright notice and permission grant shall be included in all copies or substantial portions of the source code.
12
13// Author Cumulia Illustrator
14// Date 2024-10-31
15// Version V1.1.0
16//##################################################################################################
17
18#pragma once
19
20#include <cilcore.h>
21
22#include <memory>
23#include <vector>
24#include <functional>
25
26namespace cil
27{
28 template <typename T>
30 {
31 protected:
32 std::shared_ptr<std::vector<std::shared_ptr<T>>> m_entities;
33 std::function<std::shared_ptr<Node>(std::shared_ptr<T>)> m_entity2node; // geometry and tranform only, no material
34
35 public:
36 SelectionBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
37 {
38 this->m_entities = entities;
39 this->m_entity2node = entity2node;
40 }
41
43 {
44 }
45
46 std::shared_ptr<std::vector<std::shared_ptr<T>>> entities()
47 {
48 return this->m_entities;
49 }
50
51 void setEntities(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities)
52 {
53 this->m_entities = entities;
54 }
55
56 virtual std::shared_ptr<std::vector<std::shared_ptr<Node>>> build() = 0;
57 };
58
59 template <typename T>
61 {
62 public:
63 EntityBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
64 : SelectionBuilder<T>(entities, entity2node)
65 {
66 }
67
69 {
70 }
71
72 virtual std::shared_ptr<std::vector<std::shared_ptr<Node>>> build()
73 {
74 auto nodes = _nodes();
75
76 unsigned int index = 0;
77 for (auto& entity : *this->m_entities)
78 {
79 auto node = this->m_entity2node(entity);
80 auto value = _clr4((unsigned char)index / 255.0, (unsigned char)(index >> 8) / 255.0, (unsigned char)(index >> 16) / 255.0, (unsigned char)(index >> 24) / 255.0);
81 node->material = _material(nullptr, _parameters(
82 {
83 {"index", value},
84 }
85 ), nullptr);
86 nodes->push_back(node);
87
88 index++;
89 }
90
91 return nodes;
92 }
93 };
94
95 template <typename T>
96 class FaceBuilder : public EntityBuilder<T>
97 {
98 public:
99 FaceBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
100 : EntityBuilder<T>(entities, entity2node)
101 {
102 }
103
104 virtual ~FaceBuilder()
105 {
106 }
107 };
108
109 template <typename T>
110 class VertexBuilder : public EntityBuilder<T>
111 {
112 public:
113 VertexBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
114 : EntityBuilder<T>(entities, entity2node)
115 {
116 }
117
119 {
120 }
121 };
122
123 template <typename T>
124 class EdgeBuilder : public EntityBuilder<T>
125 {
126 public:
127 EdgeBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
128 : EntityBuilder<T>(entities, entity2node)
129 {
130 }
131
132 virtual ~EdgeBuilder()
133 {
134 }
135 };
136
137 template <typename T>
139 {
140 public:
141 AttributeBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
142 : SelectionBuilder<T>(entities, entity2node)
143 {
144 }
145
147 {
148 }
149
150 virtual std::shared_ptr<std::vector<std::shared_ptr<Node>>> build()
151 {
152 auto nodes = _nodes();
153
154 for (auto& entity : *this->m_entities)
155 {
156 auto node = this->m_entity2node(entity);
157 nodes->push_back(node);
158 }
159
160 return nodes;
161 }
162 };
163
164 template <typename T>
166 {
167 public:
168 PositionBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
169 : AttributeBuilder<T>(entities, entity2node)
170 {
171 }
172
174 {
175 }
176 };
177
178 template <typename T>
180 {
181 public:
182 NormalBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
183 : AttributeBuilder<T>(entities, entity2node)
184 {
185 }
186
188 {
189 }
190 };
191
192 template <typename T>
194 {
195 public:
196 PrimitiveBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
197 : AttributeBuilder<T>(entities, entity2node)
198 {
199 }
200
202 {
203 }
204 };
205}
Definition builder.h:139
virtual ~AttributeBuilder()
Definition builder.h:146
AttributeBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:141
virtual std::shared_ptr< std::vector< std::shared_ptr< Node > > > build()
Definition builder.h:150
Definition builder.h:125
virtual ~EdgeBuilder()
Definition builder.h:132
EdgeBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:127
Definition builder.h:61
EntityBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:63
virtual ~EntityBuilder()
Definition builder.h:68
virtual std::shared_ptr< std::vector< std::shared_ptr< Node > > > build()
Definition builder.h:72
Definition builder.h:97
FaceBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:99
virtual ~FaceBuilder()
Definition builder.h:104
Definition builder.h:180
NormalBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:182
virtual ~NormalBuilder()
Definition builder.h:187
Definition builder.h:166
PositionBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:168
virtual ~PositionBuilder()
Definition builder.h:173
Definition builder.h:194
PrimitiveBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:196
virtual ~PrimitiveBuilder()
Definition builder.h:201
Definition builder.h:30
std::shared_ptr< std::vector< std::shared_ptr< T > > > entities()
Definition builder.h:46
void setEntities(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities)
Definition builder.h:51
std::shared_ptr< std::vector< std::shared_ptr< T > > > m_entities
Definition builder.h:32
virtual ~SelectionBuilder()
Definition builder.h:42
SelectionBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:36
std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> m_entity2node
Definition builder.h:33
virtual std::shared_ptr< std::vector< std::shared_ptr< Node > > > build()=0
Definition builder.h:111
virtual ~VertexBuilder()
Definition builder.h:118
VertexBuilder(const std::shared_ptr< std::vector< std::shared_ptr< T > > > &entities, const std::function< std::shared_ptr< Node >(std::shared_ptr< T >)> &entity2node)
Definition builder.h:113
Definition decal.h:23
std::shared_ptr< std::map< std::string, std::shared_ptr< Variant > > > _parameters(const std::map< std::string, std::shared_ptr< Variant > > &parameters={})
std::shared_ptr< Color4f > _clr4()
std::shared_ptr< Material > _material(const std::shared_ptr< Program > &program=nullptr, const std::shared_ptr< std::map< std::string, std::shared_ptr< Variant > > > &parameters=nullptr, const std::shared_ptr< std::vector< std::shared_ptr< State > > > &states=nullptr)
std::shared_ptr< std::vector< std::shared_ptr< Node > > > _nodes(const std::vector< std::shared_ptr< Node > > &nodes={})