Cumulia Illustrator Rendering Engine v2.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 2025-08-05
15// Version V2.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 if (node)
81 {
82 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);
83 node->material = _material(nullptr, _parameters(
84 {
85 {"index", value},
86 }
87 ), nullptr);
88 nodes->push_back(node);
89 }
90
91 index++;
92 }
93
94 return nodes;
95 }
96 };
97
98 template <typename T>
99 class FaceBuilder : public EntityBuilder<T>
100 {
101 public:
102 FaceBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
103 : EntityBuilder<T>(entities, entity2node)
104 {
105 }
106
107 virtual ~FaceBuilder()
108 {
109 }
110 };
111
112 template <typename T>
113 class VertexBuilder : public EntityBuilder<T>
114 {
115 public:
116 VertexBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
117 : EntityBuilder<T>(entities, entity2node)
118 {
119 }
120
122 {
123 }
124 };
125
126 template <typename T>
127 class EdgeBuilder : public EntityBuilder<T>
128 {
129 public:
130 EdgeBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
131 : EntityBuilder<T>(entities, entity2node)
132 {
133 }
134
135 virtual ~EdgeBuilder()
136 {
137 }
138 };
139
140 template <typename T>
142 {
143 public:
144 AttributeBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
145 : SelectionBuilder<T>(entities, entity2node)
146 {
147 }
148
150 {
151 }
152
153 virtual std::shared_ptr<std::vector<std::shared_ptr<Node>>> build()
154 {
155 auto nodes = _nodes();
156
157 for (auto& entity : *this->m_entities)
158 {
159 auto node = this->m_entity2node(entity);
160 if (node)
161 {
162 nodes->push_back(node);
163 }
164 }
165
166 return nodes;
167 }
168 };
169
170 template <typename T>
172 {
173 public:
174 PositionBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
175 : AttributeBuilder<T>(entities, entity2node)
176 {
177 }
178
180 {
181 }
182 };
183
184 template <typename T>
186 {
187 public:
188 NormalBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
189 : AttributeBuilder<T>(entities, entity2node)
190 {
191 }
192
194 {
195 }
196 };
197
198 template <typename T>
200 {
201 public:
202 PrimitiveBuilder(const std::shared_ptr<std::vector<std::shared_ptr<T>>>& entities, const std::function<std::shared_ptr<Node>(std::shared_ptr<T>)>& entity2node)
203 : AttributeBuilder<T>(entities, entity2node)
204 {
205 }
206
208 {
209 }
210 };
211}
Definition builder.h:142
virtual ~AttributeBuilder()
Definition builder.h:149
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:144
virtual std::shared_ptr< std::vector< std::shared_ptr< Node > > > build()
Definition builder.h:153
Definition builder.h:128
virtual ~EdgeBuilder()
Definition builder.h:135
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:130
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:100
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:102
virtual ~FaceBuilder()
Definition builder.h:107
Definition builder.h:186
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:188
virtual ~NormalBuilder()
Definition builder.h:193
Definition builder.h:172
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:174
virtual ~PositionBuilder()
Definition builder.h:179
Definition builder.h:200
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:202
virtual ~PrimitiveBuilder()
Definition builder.h:207
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:114
virtual ~VertexBuilder()
Definition builder.h:121
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:116
Definition decal.h:23
MaterialPtr _material(const ProgramPtr &program=nullptr, const std::shared_ptr< std::map< std::string, VariantPtr > > &parameters=nullptr, const std::shared_ptr< std::vector< StatePtr > > &states=nullptr)
Color4fPtr _clr4()
std::shared_ptr< std::vector< NodePtr > > _nodes(const std::vector< NodePtr > &nodes={})
std::shared_ptr< std::map< std::string, VariantPtr > > _parameters(const std::map< std::string, VariantPtr > &parameters={})