Subject: CGAL users discussion list
List archive
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] Surface_Mesh_Deformation help
- Date: Wed, 21 Feb 2018 08:29:47 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-phdr: 9a23:oUhYvRYgJPOqShXwMLOLVar/LSx+4OfEezUN459isYplN5qZrs6+bnLW6fgltlLVR4KTs6sC17KN9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCazbL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjul8qlrVQToiD8ZODEl7GHZhMtwjKdBrxKgoRx03orYbY6ROfZ7eK7WYNEUSndbXstJSiJPHI28YYsMAeQPM+lXoIvyqEcBoxalGQmhBvnixiNUinL436A31fkqHwHc3AwnGtIDqHrYosjrO6gJS++117XIzTTdYPNQxDzz7o/IcgogofGLQbJ7bM7dx0gxGAPCi1Wft5DlPymV1+oNqWeU8/ZgVeW1i28nrg19rCWky8A3ionNgYIV0FHE9SJlwIovIN24TFV2YdGhEJRKtiGaM5F6Td8lQ2FtoSs3zKANt5C8fCgP0psnxhjfZuSBc4eS+R3sT+KRLiliiH15f7K/gg6+8VKnyu39TMW0105KoTRDktXUt3ACzAfc5tKbRft6+EqqxDWB1xjL5+1aPUw5kbDXJp0hz7Iqi5Yfr0fOEjXrlEj0kaOabkcp9+uy5+j5bbjrp4WQO5JwhwzwKKgjmMyyDOIlOQYURWeb4/6z1Lj78E35XrpKivo2n7HcsJ/AJMQbore1AgFP0oo/8hq/ASqq3dYFkXUdI1JFfxWHj4ftO17QOvz3EfC/g1G0nDdqwfDJIKHhD43TInTflLrtZ7Vw5k5GxAYu09xS5IhYBqwDLf7uQkPxscbXDh49Mwy62ebnD9B925sFWWKLBa+ZKqLSsViU5u41JumMYJQYuDn4K/c/5v7uiWU1lkMafamsxZcXcmy3Hux6I0WFZnrhmssOEWgQsQo6VeDllVyCUSVPaHavRKI8/So2CJmmDIfGXoCimqaN3Ca9Hp1MZ2BJEEqAEXnyd9bMZ/BZYy2bJoptkycPSKO6Y44nzxCn8gHgmJR9Ke+BsBYVv5v4yNl44aX3kgsz8iA8T+uQ1GSAU3tlsGoDWzgszeE16RhmzlCZ0K9kxflcPdNW7vJNFAw9MMiPnKRBF9nuV1eZLZ+yQ1G8T4D6UGhgHOJ0+McHZgNGI/vnixnC2ySwBLpMzu6EAZU19uTX2H2jfp8hmUaD77EoihwdeuUKLXev3/ct+A3aBoqPmEKcxf7zKPYsmRXV/WLG9lKg+UFVVAkqD/fAVHEbI1TM9ZH3vxybCbCpDrsjP01KzsvQcqY=
The index used to refer to vertices is the iteration order of the
vertices. So if no modification was done before saving a ROI or a
set of control points this order should be the same when reading
the same file in your program.
HTH
Sebastien.
On 02/19/2018 10:56 PM, gligart wrote:
Hello there, I'm having troubles with surface mesh deformation in CGAL.
I explain you in details what's the matter and then I'll show you the code.
My aim is to deform a mesh surface loading a pre-saved ROI/ControlVertices
file where all the informations about the vertices are stored, the file you
could extract from using the Polyhedron Demo from the menu:
Operations->SurfaceMeshDeformation->Display and IO (TAB) and saving a file
named ROI.txt, extracting then by hand PlaneROI.txt and PlaneCV.txt simply
copying the corresponding lists of vertices from the original file) and then
I have wrote a loop where I feed the algorithm with several affine matrices
to create the new deformed meshes. If I load the ROI.txt file in the GUI of
the Polyhedron DEMO it shows that the selection is right, but if I then use
that file in the algorithm to choose which vertices to handle as control
vertices and which as part of the ROI it seems that the vertices are not
indexed as they were when creating the file for the selection, and so what I
have as a result is a messy selection of vertices deformed. Here I show you
two images to show you what I'm talking about:
Selection file Loaded in the Polyhedron Demo
https://ibb.co/eBWWwS <https://ibb.co/eBWWwS>
Deformed Mesh Result
https://ibb.co/cnYfO7 <https://ibb.co/cnYfO7>
The Deformation Matrix used for the deformation is as follow:
//////////
# 4x4 handle transformation matrix
1 0 0 0
0 0.984808 0.173648 0
0 -0.173648 0.984808 0
0 0 0 1
////////
And here I show you the same procedure applied to a simpler object, which
actually works:
Selection of the plane
https://ibb.co/kNqYbS <https://ibb.co/kNqYbS>
Deformed Mesh Result
https://ibb.co/gB2RVn <https://ibb.co/gB2RVn>
The *.cpp I'm running is based on deform_mesh_for_botsch08_format.cpp
contained in the demo folder of the Surface Mesh Deformation package, and
here there is the additional code I've used (which works for the plane nut
not for the first object):
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3>
Polyhedron;
typedef boost::graph_traits<Polyhedron>::vertex_descriptor
vertex_descriptor;
typedef boost::graph_traits<Polyhedron>::vertex_iterator
vertex_iterator;
typedef CGAL::Surface_mesh_deformation<Polyhedron,CGAL::Default,
CGAL::Default, CGAL::SRE_ARAP> Surface_mesh_deformation;
int main(int argc,char** argv)
{
Polyhedron mesh;
std::ifstream input(argv[1]);
if ( !input || !(input >> mesh) || mesh.empty() ) {
std::cerr<< argv[1] << " is not a valid off file" << std::endl;
return 1;
}
input.close();
//Personal Code
LISTT list;
ofstream Selection("PlaneSelection.sel");
// Creating Selection File from ROI and CV
list.initROI();
list.initCV();
list.writingSelection(Selection);
// Init the indices of the halfedges and the vertices.
set_halfedgeds_items_id(mesh);
//Variables
int iteratore = 0;
Surface_mesh_deformation deform_mesh(mesh);
vertex_iterator vb,ve;
boost::tie(vb, ve) = vertices(mesh);
std::string line;
std::vector<vertex_descriptor> control_vertices;
bool is_matrix_factorization_OK;
vertex_descriptor vd;
// Fine variabili
while (iteratore < 10) {
// The selection is set by a file
input.open("PlaneSelection.sel");
while(getline(input, line))
{
if (line[0]=='#') continue;
if (line[0]=='1') deform_mesh.insert_roi_vertex(*vb);
if (line[0]=='2') {
deform_mesh.insert_control_vertex(*vb);
control_vertices.push_back(*vb);
}
++vb;
if (vb==ve) break;
}
input.close();
std::cout << "Using " << control_vertices.size() << " control
vertices\n";
is_matrix_factorization_OK = deform_mesh.preprocess();
if(!is_matrix_factorization_OK){
std::cerr << "Error in preprocessing, check documentation of
preprocess()" << std::endl;
return 1;
}
std::ostringstream FileNameDef;
FileNameDef << "Deform" << iteratore << ".def";
std::string NameDef = FileNameDef.str();
cout << "Using Def " << NameDef.c_str() << endl;
input.open(NameDef.c_str());
double m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23,
hw, sink;
getline(input, line); // skip first comment line
input >> m00 >> m01 >> m02 >> m03;
input >> m10 >> m11 >> m12 >> m13;
input >> m20 >> m21 >> m22 >> m23;
input >> sink >> sink >> sink >> hw;
Kernel::Aff_transformation_3 aff(m00, m01, m02, m03, m10, m11, m12,
m13, m20, m21, m22, m23);
BOOST_FOREACH(vd, control_vertices)
{
Surface_mesh_deformation::Point pos = vd->point().transform(aff);
deform_mesh.set_target_position(vd, pos);
}
// Call the function deform() with one-time parameters:
deform_mesh.deform(1000, 1e-4);
std::ostringstream FileName;
FileName << "Plane_" << iteratore << ".off";
std::string Names = FileName.str();
// Save the deformed mesh into a file
std::ofstream output;
output.open(Names.c_str());
output << mesh;
output.close();
iteratore++;
}
return 0;
}
The writing of the .sel file works fine, as you can see from the plane,
this the code for it:
class LISTT
{
public:
fstream ROI,CV;
vector<double> xROI;
vector<double> yCV;
int k, size, toppa, check, ity;
void initROI();
void initCV();
void writingSelection(ofstream& Selection);
};
void LISTT::initROI()
{
ROI.open("/PlaneROI.txt");
if (ROI.fail())
{
cout << "Error Opening File" << endl;
exit(1);
}
double tmp;
while (ROI >> tmp)
{
xROI.push_back(tmp);
}
ROI.close();
cout << xROI.size() << " number of values in file" << endl;
// Sorted print data from vector
sort(xROI.begin(), xROI.end(), sort_function);
for (vector<double>::iterator it = xROI.begin(); it != xROI.end(); ++it)
{
// cout << *it << " ";
}
}
void LISTT::initCV()
{
// Opening file
CV.open("PlaneCV2.txt");
if (CV.fail())
{
cout << "Error Opening File" << endl;
exit(1);
}
// Reading data and storing data
double tmp1;
while (CV >> tmp1)
{
yCV.push_back(tmp1);
}
CV.close();
cout << yCV.size() << " number of values in file" << endl;
// Sorted print data from vector
sort(yCV.begin(), yCV.end(), sort_function);
for (vector<double>::iterator it = yCV.begin(); it != yCV.end(); ++it)
{
// cout << *it << " ";
}
cout << endl;
}
void LISTT::writingSelection(ofstream &Selection)
{
ity = 0;
check = 0;
toppa = 1;
k=0;
size = 10000; //Putting a bigger number of vertices (I'll directly get
it from the input mesh size)
//ROI&CV array management
for(int it = 0; it < size; it ++)
{
if (xROI[it]==it+toppa)
{
if(xROI[it]==yCV[ity])
{
Selection << 2 << endl;
ity++;
}
else Selection << 1 << endl;
k++;
}
else
{
check = xROI[it] - k - 1;
for(int itt = 0; itt < check; itt++)
{
Selection << 0 << endl;
size--; //Excluding vertices not in the ROI and not
in the CV
toppa++; //Taking count of unselected vertices
k++; //
}
if(xROI[it]==yCV[ity])
{
Selection << 2 << endl;
ity++;
}
else Selection << 1 << endl;
k++;
}
}
}
I don't understand why it works for a simpler object (plane with 841
vertices) and not for the first objects (3151 vertices).
Could you give me a hand understanding this issue?
Thank you in Advance
LV
--
Sent from: http://cgal-discuss.949826.n4.nabble.com/
- [cgal-discuss] Surface_Mesh_Deformation help, gligart, 02/19/2018
- Re: [cgal-discuss] Surface_Mesh_Deformation help, Sebastien Loriot (GeometryFactory), 02/21/2018
- Re: [cgal-discuss] Surface_Mesh_Deformation help, gligart, 02/23/2018
- Re: [cgal-discuss] Surface_Mesh_Deformation help, Sebastien Loriot (GeometryFactory), 02/21/2018
Archive powered by MHonArc 2.6.18.