Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more functionality #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/utils/vcgDefaultMesh.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// Copyright 2018 Andrea Mantovani
// https://github.com/korut94/VCGLibForParaview/tree/master/src/utils

#ifndef UTILSVCGDEFAULTMESH_H
#define UTILSVCGDEFAULTMESH_H

#include "vcg/complex/complex.h"
// stuff to define the mesh
#include <vcg/complex/complex.h>

// io
#include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export_ply.h>

// local optimization
#include <vcg/complex/algorithms/local_optimization.h>
#include <vcg/complex/algorithms/local_optimization/tri_edge_collapse_quadric.h>

namespace utils
{
Expand All @@ -21,14 +31,21 @@ class VCGDefaultVertex : public vcg::Vertex<
vcg::vertex::Coord3f,
vcg::vertex::Normal3f,
vcg::vertex::Color4b,
vcg::vertex::VFAdj,
vcg::vertex::BitFlags,
vcg::vertex::Qualityf> {};
vcg::vertex::Qualityf> {
public:
vcg::math::Quadric<double> &Qd() {return q;}
private:
vcg::math::Quadric<double> q;
};

class VCGDefaultFace : public vcg::Face<
VCGDefaultUsedTypes,
vcg::face::VertexRef,
vcg::face::Normal3f,
vcg::face::FFAdj,
vcg::face::VFAdj,
vcg::face::BitFlags,
vcg::face::Mark> {};

Expand All @@ -38,6 +55,17 @@ class VCGDefaultMesh : public vcg::tri::TriMesh<
std::vector<VCGDefaultVertex>,
std::vector<VCGDefaultFace>,
std::vector<VCGDefaultEdge>> {};

typedef BasicVertexPair<VCGDefaultVertex> VCGDefaultVertexPair;

class VCGDefaultTriEdgeCollapse: public vcg::tri::TriEdgeCollapseQuadric< VCGDefaultMesh, VCGDefaultVertexPair, VCGDefaultTriEdgeCollapse, QInfoStandard<VCGDefaultVertex> >
{
public:
typedef vcg::tri::TriEdgeCollapseQuadric< VCGDefaultMesh, VCGDefaultVertexPair, VCGDefaultTriEdgeCollapse, QInfoStandard<VCGDefaultVertex> > TECQ;
typedef VCGDefaultMesh::VertexType::EdgeType EdgeType;
inline VCGDefaultTriEdgeCollapse( const VCGDefaultVertexPair &p, int i, vcg::BaseParameterClass *pp) :TECQ(p,i,pp){}
};

} // namespace utils

#endif // UTILSVCGDEFAULTMESH_H
#endif // UTILSVCGDEFAULTMESH_H
81 changes: 76 additions & 5 deletions src/utils/vcgFactory.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Copyright 2018 Andrea Mantovani

// https://github.com/korut94/VCGLibForParaview/tree/master/src/utils

#ifndef UTILSVCGFACTORY_H
#define UTILSVCGFACTORY_H

#include "vtkCellIterator.h"
#include "vtkCellArray.h"
#include "vtkDataSet.h"
#include "vtkPolyData.h"
#include "vtkPolygon.h"
#include "vtkOutputWindow.h"
#include "vtkPoints.h"

#include "vcg/complex/algorithms/create/platonic.h"

namespace utils
Expand All @@ -25,6 +29,12 @@ class vcgFactory
template <typename MeshType>
static int FromVCGMeshExtractVTKPoints(const MeshType &mesh, vtkPoints *points);

template <typename MeshType>
static int FromVCGMeshExtractFacesVertices(const MeshType &mesh, int* faces, double *vertices);

template <typename MeshType>
static int FromVCGMeshBuildVTKPolyData(const MeshType &mesh, vtkPolyData *polydata);

template <typename MeshType>
static int FromVTKDataSetBuildVCGMesh(MeshType &mesh, vtkDataSet *data);

Expand All @@ -40,8 +50,8 @@ class vcgFactory

template <typename MeshType>
int vcgFactory::FromVTKDataSetExtractVCGVertexes(
vtkDataSet *data,
std::vector<vcg::Point3f> &coords,
vtkDataSet *data,
std::vector<vcg::Point3f> &coords,
std::vector<vcg::Point3i> &ids) {
vtkOutputWindow *outputWindow = vtkOutputWindow::GetInstance();

Expand Down Expand Up @@ -123,6 +133,67 @@ int vcgFactory::FromVCGMeshExtractVTKPoints(const MeshType &mesh, vtkPoints *poi

return 1;
}
} // namespace utils

#endif // UTILSVCGFACTORY_H
template <typename MeshType>
int vcgFactory::FromVCGMeshExtractFacesVertices(const MeshType &mesh, int* faces, double *vertices) {
// Only works with triangular meshes only (no face with more than 3 vertices)

int i = 0;
vcg::SimpleTempData<typename const MeshType::VertContainer, int> indices(mesh.vert);
for (auto &&vertex : mesh.vert) {
indices[vertex] = i++;
}
i = 0;
for (auto &&f : mesh.face) {
for (int k = 0; k < f.VN(); ++k)
faces[3 * i + k] = indices[f.cV(k)];
i++;
}

i = 0;
for (auto &&vertex : mesh.vert) {
auto point = vertex.P();
vertices[3 * i] = point.X();
vertices[3 * i + 1] = point.Y();
vertices[3 * i + 2] = point.Z();
i++;
}

return 1;
}

template <typename MeshType>
int vcgFactory::FromVCGMeshBuildVTKPolyData(const MeshType &mesh, vtkPolyData *polydata) {

// Only for triangular polygons

vtkSmartPointer<vtkCellArray> polygons = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

int* faces = new int[3 * mesh.fn];
double *vertices = new double[3 * mesh.vn];
int res = FromVCGMeshExtractFacesVertices(mesh, faces, vertices);

for (int i = 0; i < mesh.vn; i++)
points->InsertNextPoint(vertices[3 * i], vertices[3 * i + 1], vertices[3 * i + 2]);

polygon->GetPointIds()->SetNumberOfIds(3);
for (int i = 0; i < mesh.fn; i++) {
polygon->GetPointIds()->SetId(0, faces[3 * i]);
polygon->GetPointIds()->SetId(1, faces[3 * i + 1]);
polygon->GetPointIds()->SetId(2, faces[3 * i + 2]);
polygons->InsertNextCell(polygon);
}

polydata->SetPoints(points);
polydata->SetPolys(polygons);

delete faces;
delete vertices;

return 1;
}
} // namespace utils

#endif // UTILSVCGFACTORY_H