Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PoissonReconstructionT.cc
1 //=============================================================================
2 //
3 // CLASS PoissonReconstructionT - IMPLEMENTATION
4 //
5 //=============================================================================
6 
7 #define ACG_POISSONRECONSTRUCTIONT_C
8 
9 //== INCLUDES =================================================================
10 
11 #include "PoissonReconstructionT.hh"
12 
13 
14 //== NAMESPACES ===============================================================
15 
16 namespace ACG {
17 
18 //== IMPLEMENTATION ==========================================================
19 
20 void DumpOutput( const char* format , ... )
21 {
22  va_list args;
23  va_start( args , format );
24  vprintf( format , args );
25  va_end( args );
26 }
27 
28 template <class MeshT>
29 bool
30 PoissonReconstructionT<MeshT>::
31 run( std::vector< Real >& _pt_data, MeshT& _mesh, const Parameter& _parameter )
32 {
33 
34  m_parameter = _parameter;
35 
36  Real isoValue = 0;
37 
38  Octree<2> tree;
39 #ifdef USE_OMP
40  tree.threads = omp_get_num_procs();
41 #else
42  tree.threads = 1;
43 #endif
44  TreeOctNode::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE );
45 
46  std::cerr << "Tree construction with depth " << m_parameter.Depth << std::endl;
47  tree.setBSplineData( m_parameter.Depth );
48  double maxMemoryUsage;
49  tree.maxMemoryUsage=0;
51  int pointCount = tree.setTreeMemory( _pt_data , m_parameter.Depth , m_parameter.MinDepth , m_parameter.Depth , Real(m_parameter.SamplesPerNode),
52  m_parameter.Scale , m_parameter.Confidence , m_parameter.PointWeight , m_parameter.AdaptiveExponent , xForm );
53 
54  if (pointCount <= 0)
55  {
56  std::cerr << "Invalid Input Points" << std::endl;
57  return false;
58  }
59 
60  std::cerr << "Tree Clipping" << std::endl;
61 
62  tree.ClipTree();
63 
64  std::cerr << "Tree Finalize" << std::endl;
65  tree.finalize( m_parameter.IsoDivide );
66 
67  DumpOutput( "Input Points: %d\n" , pointCount );
68  DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() );
69  DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
70 
71  maxMemoryUsage = tree.maxMemoryUsage;
72  tree.maxMemoryUsage=0;
73  tree.SetLaplacianConstraints();
74  DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );
75  maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
76 
77  tree.maxMemoryUsage=0;
78  tree.LaplacianMatrixIteration( m_parameter.SolverDivide, m_parameter.ShowResidual, m_parameter.MinIters, m_parameter.SolverAccuracy, m_parameter.Depth, m_parameter.FixedIters );
79  DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
80  maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
81 
82  CoredFileMeshData mesh;
83  if( m_parameter.Verbose ) tree.maxMemoryUsage=0;
84  double time=Time();
85  isoValue = tree.GetIsoValue();
86  DumpOutput( "Got average in: %f\n" , Time()-time );
87  DumpOutput( "Iso-Value: %e\n" , isoValue );
88 
89  tree.maxMemoryUsage = 0;
90  tree.GetMCIsoTriangles( isoValue , m_parameter.IsoDivide , &mesh );
91 
92  _mesh.clear();
93  mesh.resetIterator();
94 
95  DumpOutput( "Time for Iso: %f\n" , Time()-time );
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 // int nr_vertices=int(mesh.outOfCorePointCount()+mesh.inCorePoints.size());
108  int nr_faces=mesh.polygonCount();
109 
110  mesh.resetIterator();
111 
112  //
113  // describe vertex and face properties
114  //
115 
116  // write vertices
118  for( int i=0 ; i < int( mesh.inCorePoints.size() ) ; i++ )
119  {
120  p = mesh.inCorePoints[i];
121  _mesh.add_vertex( typename MeshT::Point(p[0],p[1],p[2]) );
122  }
123  for( int i=0; i<mesh.outOfCorePointCount() ; i++ )
124  {
125  mesh.nextOutOfCorePoint(p);
126  _mesh.add_vertex( typename MeshT::Point(p[0],p[1],p[2]) );
127 
128  } // for, write vertices
129 
130  // write faces
131  std::vector< CoredVertexIndex > polygon;
132  for( int i=0 ; i<nr_faces ; i++ )
133  {
134  //
135  // create and fill a struct that the ply code can handle
136  //
137  mesh.nextPolygon( polygon );
138  std::vector< typename MeshT::VertexHandle > face;
139  for( int i=0 ; i<int( polygon.size() ) ; i++ )
140  if( polygon[i].inCore ) face.push_back( _mesh.vertex_handle( polygon[i].idx ) );
141  else face.push_back( _mesh.vertex_handle( polygon[i].idx + int( mesh.inCorePoints.size() ) ) );
142 
143  _mesh.add_face( face );
144 
145  } // for, write faces
146 
147  _mesh.update_normals();
148 
149  return true;
150 }
151 
152 //-----------------------------------------------------------------------------
153 
154 
155 
156 //=============================================================================
157 } // namespace ACG
158 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51