35 for (
unsigned int i = 0; i <
shapes.size(); i++)
55 ss <<
"La scene comporte " <<
vertices.size() <<
" vertex." << std::endl;
56 for (
unsigned int i = 0; i <
vertices.size(); i++)
61 ss <<
"La scene comporte " <<
shapes.size() <<
" shapes." << std::endl;
62 switch (accelerator_id)
112 std::map<vec3, unsigned int, compVec>::iterator it =
registeredVertices.find(newVertex);
120 index =
static_cast<unsigned int>(
vertices.size());
138 unsigned int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0, p8 = 0;
141 addVertex(
vec3(origine.x + dimension.x, origine.y, origine.z), p2);
142 addVertex(
vec3(origine.x + dimension.x, origine.y + dimension.y, origine.z), p3);
143 addVertex(
vec3(origine.x, origine.y + dimension.y, origine.z), p4);
144 addVertex(
vec3(origine.x, origine.y, origine.z + dimension.z), p5);
145 addVertex(
vec3(origine.x + dimension.x, origine.y, origine.z + dimension.z), p6);
146 addVertex(
vec3(origine.x + dimension.x, origine.y + dimension.y, origine.z + dimension.z), p7);
147 addVertex(
vec3(origine.x, origine.y + dimension.y, origine.z + dimension.z), p8);
167 std::vector<Shape*> vec;
168 for (
unsigned int i = 0; i <
shapes.size(); i++)
170 if (
shapes.at(i)->form() == shape_type)
172 vec.push_back(
shapes.at(i));
181 long long nb_vertex =
vertices.size();
182 long long nb_faces =
shapes.size();
185 std::deque<std::string> file_content;
188 file_content.push_back(std::string(
"ply\n"));
189 file_content.push_back(std::string(
"format ascii 1.0\n"));
190 file_content.push_back(std::string(
"element vertex ") + std::to_string(nb_vertex) + std::string(
"\n"));
191 file_content.push_back(std::string(
"property float x\n"));
192 file_content.push_back(std::string(
"property float y\n"));
193 file_content.push_back(std::string(
"property float z\n"));
194 file_content.push_back(std::string(
"element face ") + std::to_string(nb_faces) + std::string(
"\n"));
195 file_content.push_back(std::string(
"property list uchar int vertex_indices\n"));
196 file_content.push_back(std::string(
"property uchar red\n"));
197 file_content.push_back(std::string(
"property uchar green\n"));
198 file_content.push_back(std::string(
"property uchar blue\n"));
199 file_content.push_back(std::string(
"end_header\n"));
202 for (
unsigned int i = 0; i <
vertices.size(); i++)
204 line = std::to_string(
static_cast<long double>(
vertices.at(i).x)) +
" " +
205 std::to_string(
static_cast<long double>(
vertices.at(i).y)) +
" " +
206 std::to_string(
static_cast<long double>(
vertices.at(i).z)) +
"\n";
207 file_content.push_back(line);
211 vector<unsigned int>* vertice_index =
nullptr;
212 for (
unsigned int i = 0; i <
shapes.size(); i++)
219 vertice_index =
shapes.at(i)->getLocalVertices();
220 file_content.push_back(std::to_string(
static_cast<long long>(3)) +
" " +
221 std::to_string(
static_cast<long long>(vertice_index->at(0))) +
" " +
222 std::to_string(
static_cast<long long>(vertice_index->at(1))) +
" " +
223 std::to_string(
static_cast<long long>(vertice_index->at(2))) +
" " +
224 std::string(
"0 255 0\n"));
228 ofstream out(fileName, ios::out);
229 for (
unsigned int i = 0; i < file_content.size(); i++)
231 out << file_content.at(i);
239 ifstream in(fileName.c_str());
241 int nb_vertex = 0, nb_faces = 0;
243 if (keyword !=
"ply")
245 std::cerr <<
"Read: " + keyword +
"\n" + fileName +
" is not a ply file !" << std::endl;
248 in >> keyword >> keyword >> keyword;
249 in >> keyword >> keyword >> nb_vertex;
250 in >> keyword >> keyword >> keyword;
251 in >> keyword >> keyword >> keyword;
252 in >> keyword >> keyword >> keyword;
253 in >> keyword >> keyword >> nb_faces;
254 in >> keyword >> keyword >> keyword >> keyword >> keyword;
255 in >> keyword >> keyword >> keyword;
256 bool material =
false;
257 if (keyword ==
"material_index")
260 in >> keyword >> keyword >> keyword;
262 in >> keyword >> keyword >> keyword;
263 in >> keyword >> keyword >> keyword;
266 in >> keyword >> keyword >> keyword;
267 in >> keyword >> keyword >> keyword >> keyword >> keyword;
270 float x = NAN, y = NAN, z = NAN;
272 for (
int i = 0; i < nb_vertex; i++)
278 ss <<
"La scene lue comporte " << nb_vertex <<
" vertex." << std::endl;
279 int i1 = 0, i2 = 0, i3 = 0;
283 for (
int i = 0; i < nb_faces; i++)
285 in >> n >> i1 >> i2 >> i3;
288 in >> keyword >> keyword >> keyword;
291 std::cerr <<
"The shape " << i <<
" is not a Triangle !" << std::endl;
296 ss <<
"La scene lue comporte " << nb_faces <<
" shapes." << std::endl;
virtual bool build()
Build this accelerator.
void setIntersectionChoice(leafTreatment::treatment _intersectionChoice=leafTreatment::FIRST)
static AcousticRaytracerConfiguration * get()
Get access to the configuration.
bool isNull
True if the BBox is initialized, false if not.
A Bounding Volume Hierarchy (BVH) Accelerator.
Regular grid Accelerator.
K-d tree Accelerator (based on space splitting)
void import_from_ply(std::string fileName)
Import a Scene from a PLY format file named fileName.
void clean()
Clear all arrays.
std::vector< Shape * > shapes
Array of pointers to the shapes.
std::vector< Shape * > * getShapes()
Return all the shapes.
bool getIndex(vec3 &search, unsigned int &result)
Get the index of a vertex in the vertices array.
void export_to_ply(std::string fileName)
Export the Scene to a PLY format file named fileName.
unsigned int compteurFace
Faces counter.
Accelerator * accelerator
Pointer to the accelerator.
void addShape(Shape *shape)
Add a shape to the list.
Shape * addTriangle(unsigned int i1, unsigned int i2, unsigned int i3, Material *m, const bool &isSol=false)
Add a triangle to the scene built with the vertices array.
BBox globalBox
Bounding box of the Scene.
unsigned int compteurPrimitive
Primitives counter.
void addBuilding(vec3 origine, vec3 dimension, Material *m)
Add a building to the scene.
bool addVertex(const vec3 &newVertex, unsigned int &index)
Add a vertex to the vertices array.
bool getVertex(unsigned int &search, vec3 &result)
Get a vertex from the vertices array with its index.
std::vector< vec3 > vertices
All the vertices used by the different shapes.
std::map< vec3, unsigned int, compVec > registeredVertices
Association between a vertex and his index in vertices.
bool finish(int accelerator_id=1, leafTreatment::treatment _intersectionChoice=leafTreatment::FIRST)
Build the selected accelerator on the scene.
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
base_vec3< decimal > vec3