//Completed Voronoi Shatter distribution function: uniformDistributionPoints std::list<MeshData> voronoiShatter_uniformDistributionPoints(MeshData &meshData, int numPoints, bool doDisjointMesh, bool useDelaunay, double bCriteria, double sCriteria) { //Get Bounding Box std::pair<PointCGAL,PointCGAL> boundingBox = getMeshBoundingBox(meshData); KDPoint bboxMin = converPointExactToInexact(boundingBox.first); KDPoint bboxMax = converPointExactToInexact(boundingBox.second); //Generate random points std::list<KDPoint> randomPoints = randomPointsInBox(numPoints, bboxMin, bboxMax); //------------ TEST SAVED POINTS ------------- /* //Save Points for test std::ofstream out("voronoi_random_points_test_benchmark.ser", std::ios::binary); std::list<KDPoint>::iterator pointsIterator; for(pointsIterator = randomPoints.begin(); pointsIterator != randomPoints.end(); ++pointsIterator) { KDPoint ppp = *pointsIterator; //std::cout << "Punto Random save: " << ppp.x() << ", " << ppp.y() << ", " << ppp.z() << std::endl; out.write((char*)&ppp, sizeof(ppp)); } out.close(); */ /* //Load Points for test //std::list<KDPoint> randomPoints; randomPoints.clear(); std::ifstream in("voronoi_random_points_test.ser", std::ios::binary); for (unsigned int i = 0; i < 5; i++) { KDPoint temp; in.read((char*)&temp, sizeof(temp)); randomPoints.push_back(temp); } in.close(); */ //------------ TEST SAVED POINTS ------------- //Compute Voronoi Shatter std::list<MeshData> shatteredMeshes = voronoiShatter(meshData, randomPoints, useDelaunay, bCriteria, sCriteria); if (doDisjointMesh) { //Disjoint meshes shatteredMeshes = disjointNonContiguousListMeshes(shatteredMeshes); } //Translate generated shattered meshes in barycenter //std::list<TranslatedMeshData> translatedMeshData = centerMeshesInBarycenter(shatteredMeshes); //This is moved out this function //return translatedMeshData; return shatteredMeshes; }
int main(int argc, char** args) { // check the range of the values in this mesh ParameterReader pd; bool use_mesh_file = atof(pd.getData("use_mesh_file").c_str()); if(use_mesh_file) { // this works for a single mesh PangaeaMeshData inputMesh; std::string input_file = pd.getData("input_mesh_file"); std::string output_file = pd.getData("output_mesh_file"); PangaeaMeshIO::loadfromFile(input_file, inputMesh); vector<vector<double> > bbox; getMeshBoundingBox(inputMesh, bbox); double xrange = bbox[0][1] - bbox[0][0]; double yrange = bbox[1][1] - bbox[1][0]; double zrange = bbox[2][1] - bbox[2][0]; cout << "x_range: " << xrange << endl; cout << "y_range: " << yrange << endl; cout << "z_range: " << zrange << endl; double factor = 400.0 / zrange; cout << "scaling factor is: " << factor << endl; // scale the mesh up scaleMeshUp(inputMesh, factor); PangaeaMeshIO::writeToFile(output_file, inputMesh); }else { // this works for a heirachy of meshes PangaeaMeshData inputMesh; std::string input_format = pd.getData("input_mesh_format"); std::string output_format = pd.getData("output_mesh_format"); std::string input_list_str = pd.getData("input_list"); std::stringstream input_list(input_list_str); int number; vector<int> input_list_vector; input_list >> number; while( !input_list.fail() ) { input_list_vector.push_back(number); input_list >> number; } double factor = 0; char buffer[BUFFER_SIZE]; for(int i = 0; i < input_list_vector.size(); ++i) { stringstream input_file; sprintf(buffer, input_format.c_str(), input_list_vector[i]); input_file << buffer; //memset(&buffer[0], 0, sizeof(buffer)); stringstream output_file; sprintf(buffer, output_format.c_str(), input_list_vector[i]); output_file << buffer; //memset(&buffer[0], 0, sizeof(buffer)); PangaeaMeshIO::loadfromFile(input_file.str(), inputMesh); if(factor == 0) // if this is the first frame { vector<vector<double> > bbox; getMeshBoundingBox(inputMesh, bbox); double xrange = bbox[0][1] - bbox[0][0]; double yrange = bbox[1][1] - bbox[1][0]; double zrange = bbox[2][1] - bbox[2][0]; cout << "x_range: " << xrange << endl; cout << "y_range: " << yrange << endl; cout << "z_range: " << zrange << endl; factor = 400.0 / zrange; cout << "scaling factor is: " << factor << endl; } // scale the mesh up scaleMeshUp(inputMesh, factor); PangaeaMeshIO::writeToFile(output_file.str(), inputMesh); } } }