34 for (
unsigned int i = 0; i <
shapes.size(); i++)
53 switch (accelerator_id)
103 std::map<vec3, unsigned int, compVec>::iterator it =
registeredVertices.find(newVertex);
111 index =
static_cast<unsigned int>(
vertices.size());
129 unsigned int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0, p8 = 0;
132 addVertex(
vec3(origine.x + dimension.x, origine.y, origine.z), p2);
133 addVertex(
vec3(origine.x + dimension.x, origine.y + dimension.y, origine.z), p3);
134 addVertex(
vec3(origine.x, origine.y + dimension.y, origine.z), p4);
135 addVertex(
vec3(origine.x, origine.y, origine.z + dimension.z), p5);
136 addVertex(
vec3(origine.x + dimension.x, origine.y, origine.z + dimension.z), p6);
137 addVertex(
vec3(origine.x + dimension.x, origine.y + dimension.y, origine.z + dimension.z), p7);
138 addVertex(
vec3(origine.x, origine.y + dimension.y, origine.z + dimension.z), p8);
158 std::vector<Shape*> vec;
159 for (
unsigned int i = 0; i <
shapes.size(); i++)
161 if (
shapes.at(i)->form() == shape_type)
163 vec.push_back(
shapes.at(i));
172 long long nb_vertex =
vertices.size();
173 long long nb_faces =
shapes.size();
176 std::deque<std::string> file_content;
179 file_content.push_back(std::string(
"ply\n"));
180 file_content.push_back(std::string(
"format ascii 1.0\n"));
181 file_content.push_back(std::string(
"element vertex ") + std::to_string(nb_vertex) + std::string(
"\n"));
182 file_content.push_back(std::string(
"property float x\n"));
183 file_content.push_back(std::string(
"property float y\n"));
184 file_content.push_back(std::string(
"property float z\n"));
185 file_content.push_back(std::string(
"element face ") + std::to_string(nb_faces) + std::string(
"\n"));
186 file_content.push_back(std::string(
"property list uchar int vertex_indices\n"));
187 file_content.push_back(std::string(
"property uchar red\n"));
188 file_content.push_back(std::string(
"property uchar green\n"));
189 file_content.push_back(std::string(
"property uchar blue\n"));
190 file_content.push_back(std::string(
"end_header\n"));
193 for (
unsigned int i = 0; i <
vertices.size(); i++)
195 line = std::to_string(
static_cast<long double>(
vertices.at(i).x)) +
" " +
196 std::to_string(
static_cast<long double>(
vertices.at(i).y)) +
" " +
197 std::to_string(
static_cast<long double>(
vertices.at(i).z)) +
"\n";
198 file_content.push_back(line);
202 std::vector<unsigned int>* vertice_index =
nullptr;
203 for (
unsigned int i = 0; i <
shapes.size(); i++)
210 vertice_index =
shapes.at(i)->getLocalVertices();
211 file_content.push_back(std::to_string(
static_cast<long long>(3)) +
" " +
212 std::to_string(
static_cast<long long>(vertice_index->at(0))) +
" " +
213 std::to_string(
static_cast<long long>(vertice_index->at(1))) +
" " +
214 std::to_string(
static_cast<long long>(vertice_index->at(2))) +
" " +
215 std::string(
"0 255 0\n"));
219 std::ofstream out(fileName, std::ios::out);
220 for (
unsigned int i = 0; i < file_content.size(); i++)
222 out << file_content.at(i);
230 std::ifstream in(fileName.c_str());
232 int nb_vertex = 0, nb_faces = 0;
234 if (keyword !=
"ply")
236 std::cerr <<
"Read: " + keyword +
"\n" + fileName +
" is not a ply file !" << std::endl;
239 in >> keyword >> keyword >> keyword;
240 in >> keyword >> keyword >> nb_vertex;
241 in >> keyword >> keyword >> keyword;
242 in >> keyword >> keyword >> keyword;
243 in >> keyword >> keyword >> keyword;
244 in >> keyword >> keyword >> nb_faces;
245 in >> keyword >> keyword >> keyword >> keyword >> keyword;
246 in >> keyword >> keyword >> keyword;
247 bool material =
false;
248 if (keyword ==
"material_index")
251 in >> keyword >> keyword >> keyword;
253 in >> keyword >> keyword >> keyword;
254 in >> keyword >> keyword >> keyword;
257 in >> keyword >> keyword >> keyword;
258 in >> keyword >> keyword >> keyword >> keyword >> keyword;
261 float x = NAN, y = NAN, z = NAN;
263 for (
int i = 0; i < nb_vertex; i++)
269 int i1 = 0, i2 = 0, i3 = 0;
273 for (
int i = 0; i < nb_faces; i++)
275 in >> n >> i1 >> i2 >> i3;
278 in >> keyword >> keyword >> keyword;
281 std::cerr <<
"The shape " << i <<
" is not a Triangle !" << 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