mirror of https://github.com/CGAL/cgal
no tabs
This commit is contained in:
parent
b607697dd9
commit
7d75573270
|
|
@ -30,164 +30,164 @@ std::string result;
|
||||||
|
|
||||||
void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, double criteria_b, int iteration_number, double*& newVertices, int*& vCount, int*& newFaces, int*& fCount, int fileNum)
|
void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, double criteria_b, int iteration_number, double*& newVertices, int*& vCount, int*& newFaces, int*& fCount, int fileNum)
|
||||||
{
|
{
|
||||||
CDT cdt;
|
CDT cdt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<Vertex_handle> cdt_Vh_Boundary;
|
vector<Vertex_handle> cdt_Vh_Boundary;
|
||||||
|
|
||||||
for (int i = 0; i < vert_count; ++i)
|
for (int i = 0; i < vert_count; ++i)
|
||||||
{
|
{
|
||||||
Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1]));
|
Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1]));
|
||||||
cdt_Vh_Boundary.push_back(vh);
|
cdt_Vh_Boundary.push_back(vh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert Constrain
|
// insert Constrain
|
||||||
for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i)
|
for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i)
|
||||||
{
|
{
|
||||||
cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]);
|
cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]);
|
||||||
}
|
}
|
||||||
cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]);
|
cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]);
|
||||||
|
|
||||||
// refine and optimize mesh
|
// refine and optimize mesh
|
||||||
|
|
||||||
Mesher mesher(cdt);
|
Mesher mesher(cdt);
|
||||||
mesher.set_criteria(Criteria(criteria_a, criteria_b));
|
mesher.set_criteria(Criteria(criteria_a, criteria_b));
|
||||||
mesher.refine_mesh();
|
mesher.refine_mesh();
|
||||||
CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = iteration_number);
|
CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = iteration_number);
|
||||||
|
|
||||||
|
|
||||||
// make index pair
|
// make index pair
|
||||||
vector <CDT::Vertex_handle> visitedVertices; // collect visited vertices
|
vector <CDT::Vertex_handle> visitedVertices; // collect visited vertices
|
||||||
|
|
||||||
map <CDT::Vertex_handle, int> indexList; // create a map to note the index
|
map <CDT::Vertex_handle, int> indexList; // create a map to note the index
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it)
|
for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it)
|
||||||
{
|
{
|
||||||
|
|
||||||
CDT::Vertex_handle vh = v_it->handle();
|
CDT::Vertex_handle vh = v_it->handle();
|
||||||
indexList[vh] = i;
|
indexList[vh] = i;
|
||||||
visitedVertices.push_back(vh);
|
visitedVertices.push_back(vh);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert data into double array
|
// Convert data into double array
|
||||||
int vNum = cdt.number_of_vertices();
|
int vNum = cdt.number_of_vertices();
|
||||||
|
|
||||||
newVertices = new double[vNum * 3];
|
newVertices = new double[vNum * 3];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi)
|
for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi)
|
||||||
{
|
{
|
||||||
newVertices[i] = vi->point()[0];
|
newVertices[i] = vi->point()[0];
|
||||||
i += 1;
|
i += 1;
|
||||||
newVertices[i] = vi->point()[1];
|
newVertices[i] = vi->point()[1];
|
||||||
i += 1;
|
i += 1;
|
||||||
newVertices[i] = 0;
|
newVertices[i] = 0;
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vertexCount = vNum;
|
int vertexCount = vNum;
|
||||||
vCount = &vertexCount;
|
vCount = &vertexCount;
|
||||||
|
|
||||||
int num_face_in_domain = 0;
|
int num_face_in_domain = 0;
|
||||||
|
|
||||||
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
|
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
|
||||||
{
|
{
|
||||||
CDT::Face_handle face = f_it;
|
CDT::Face_handle face = f_it;
|
||||||
if (face->is_in_domain())
|
if (face->is_in_domain())
|
||||||
{
|
{
|
||||||
num_face_in_domain++;
|
num_face_in_domain++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
newFaces = new int[num_face_in_domain * 3];
|
newFaces = new int[num_face_in_domain * 3];
|
||||||
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
|
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
|
||||||
{
|
{
|
||||||
CDT::Face_handle face = f_it;
|
CDT::Face_handle face = f_it;
|
||||||
|
|
||||||
if (face->is_in_domain())
|
if (face->is_in_domain())
|
||||||
{
|
{
|
||||||
newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second);
|
newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second);
|
||||||
i += 1;
|
i += 1;
|
||||||
newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second);
|
newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second);
|
||||||
i += 1;
|
i += 1;
|
||||||
newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second);
|
newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int faceCount = num_face_in_domain;
|
int faceCount = num_face_in_domain;
|
||||||
fCount = &faceCount;
|
fCount = &faceCount;
|
||||||
|
|
||||||
|
|
||||||
// print
|
// print
|
||||||
std::stringstream outputFile;
|
std::stringstream outputFile;
|
||||||
|
|
||||||
if (fCount && newFaces) {
|
if (fCount && newFaces) {
|
||||||
outputFile << "\nRemeshed faces (" << *fCount << "):\n";
|
outputFile << "\nRemeshed faces (" << *fCount << "):\n";
|
||||||
for (int i = 0; i < (*fCount) * 3; i += 3) {
|
for (int i = 0; i < (*fCount) * 3; i += 3) {
|
||||||
outputFile << newFaces[i] << " " << newFaces[i + 1] << " " << newFaces[i + 2] << "\n";
|
outputFile << newFaces[i] << " " << newFaces[i + 1] << " " << newFaces[i + 2] << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileNum == 1)
|
if(fileNum == 1)
|
||||||
{
|
{
|
||||||
result = outputFile.str();
|
result = outputFile.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(result == outputFile.str());
|
assert(result == outputFile.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
double vert_xyz_array[] = {
|
double vert_xyz_array[] = {
|
||||||
3375.4981, 1935.35224056, 0.0,
|
3375.4981, 1935.35224056, 0.0,
|
||||||
3350.77259333, 2066.38188194, 0.0,
|
3350.77259333, 2066.38188194, 0.0,
|
||||||
3210.83712383, 2054.53004190, 0.0,
|
3210.83712383, 2054.53004190, 0.0,
|
||||||
3068.88, 2060.98161842, 0.0,
|
3068.88, 2060.98161842, 0.0,
|
||||||
3034.24939361, 2066.55369658, 0.0,
|
3034.24939361, 2066.55369658, 0.0,
|
||||||
3025.6776, 2008.40156297, 0.0,
|
3025.6776, 2008.40156297, 0.0,
|
||||||
3013.23241519, 1927.9864, 0.0,
|
3013.23241519, 1927.9864, 0.0,
|
||||||
3033.36312437, 1924.87291062, 0.0,
|
3033.36312437, 1924.87291062, 0.0,
|
||||||
3078.68871988, 1917.86131994, 0.0,
|
3078.68871988, 1917.86131994, 0.0,
|
||||||
3124.01437021, 1910.85008365, 0.0,
|
3124.01437021, 1910.85008365, 0.0,
|
||||||
3167.66255113, 1908.86629111, 0.0,
|
3167.66255113, 1908.86629111, 0.0,
|
||||||
3169.83178711, 1908.76770020, 0.0,
|
3169.83178711, 1908.76770020, 0.0,
|
||||||
3215.64920401, 1906.68531674, 0.0,
|
3215.64920401, 1906.68531674, 0.0,
|
||||||
3260.96808047, 1913.74020504, 0.0,
|
3260.96808047, 1913.74020504, 0.0,
|
||||||
3306.03738982, 1922.24487242, 0.0,
|
3306.03738982, 1922.24487242, 0.0,
|
||||||
3351.10669914, 1930.74953992, 0.0
|
3351.10669914, 1930.74953992, 0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
size_t vert_count = 16;
|
size_t vert_count = 16;
|
||||||
double criteria_a = 0.125;
|
double criteria_a = 0.125;
|
||||||
double criteria_b = 36.691771392;
|
double criteria_b = 36.691771392;
|
||||||
int iteration_number = 20;
|
int iteration_number = 20;
|
||||||
|
|
||||||
double* newVertices = nullptr;
|
double* newVertices = nullptr;
|
||||||
int* vCount = nullptr;
|
int* vCount = nullptr;
|
||||||
int* newFaces = nullptr;
|
int* newFaces = nullptr;
|
||||||
int* fCount = nullptr;
|
int* fCount = nullptr;
|
||||||
|
|
||||||
for (int i = 1; i <= 2; ++i)
|
for (int i = 1; i <= 2; ++i)
|
||||||
{
|
{
|
||||||
CGAL_Remesh(vert_xyz_array, vert_count, criteria_a, criteria_b, iteration_number, newVertices, vCount, newFaces, fCount, i);
|
CGAL_Remesh(vert_xyz_array, vert_count, criteria_a, criteria_b, iteration_number, newVertices, vCount, newFaces, fCount, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << "\nDone";
|
std::cout << "\nDone";
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue