Debian Codegraph @

src/thirdparty/PoissonRecon/AdaptiveTreeVisualization.cpp

raw
1 /*
2 Copyright (c) 2016, Michael Kazhdan
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28
29 #include "PreProcessor.h"
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include <float.h>
35 #include "MyMiscellany.h"
36 #include "CmdLineParser.h"
37 #include "PPolynomial.h"
38 #include "FEMTree.h"
39 #include "Ply.h"
40 #include "VertexFactory.h"
41 #include "Image.h"
42 #include "RegularGrid.h"
43 #include "DataStream.imp.h"
44 #include "Reconstructors.h"
45
46 using namespace PoissonRecon;
47
48 CmdLineParameter< char* >
49 In( "in" ) ,
50 Samples( "samples" ) ,
51 OutMesh( "mesh" ) ,
52 OutTree( "tree" ) ,
53 OutSlice( "slice" ) ,
54 OutGrid( "grid" );
55
56 CmdLineReadable
57 PolygonMesh( "polygonMesh" ) ,
58 NonManifold( "nonManifold" ) ,
59 FlipOrientation( "flip" ) ,
60 ASCII( "ascii" ) ,
61 NonLinearFit( "nonLinearFit" ) ,
62 PrimalGrid( "primalGrid" ) ,
63 Verbose( "verbose" );
64
65 CmdLineParameter< int >
66 ParallelType( "parallel" , 0 ) ,
67 ScheduleType( "schedule" , (int)ThreadPool::Schedule ) ,
68 ThreadChunkSize( "chunkSize" , (int)ThreadPool::ChunkSize ) ,
69 IsoSlabDepth( "sDepth" , 0 ) ,
70 IsoSlabStart( "sStart" , 0 ) ,
71 IsoSlabEnd ( "sEnd" , 1 ) ,
72 SliceDepth( "sliceDepth" ) ,
73 SliceIndex( "sliceIndex" ) ,
74 TreeScale( "treeScale" , 1 ) ,
75 TreeDepth( "treeDepth" , -1 );
76
77
78 CmdLineParameter< float >
79 IsoValue( "iso" , 0.f );
80
81 CmdLineReadable* params[] =
82 {
83 &In ,
84 &Samples ,
85 &OutMesh , &NonManifold , &PolygonMesh , &FlipOrientation , &ASCII , &NonLinearFit , &IsoValue ,
86 &OutGrid , &PrimalGrid ,
87 &OutTree , &TreeScale , &TreeDepth ,
88 &Verbose ,
89 &ParallelType ,
90 &ScheduleType ,
91 &ThreadChunkSize ,
92 &IsoSlabDepth , &IsoSlabStart , &IsoSlabEnd ,
93 &OutSlice , &SliceDepth , &SliceIndex,
94 NULL
95 };
96
97 void ShowUsage( char* ex )
98 {
99 printf( "Usage: %s\n" , ex );
100 printf( "\t --%s <input tree>\n" , In.name );
101 printf( "\t[--%s sample positions>]\n" , Samples.name );
102 printf( "\t[--%s <ouput triangle mesh>]\n" , OutMesh.name );
103 printf( "\t[--%s <ouput grid>]\n" , OutGrid.name );
104 printf( "\t[--%s <ouput tree grid>]\n" , OutTree.name );
105 printf( "\t[--%s <tree scale factor>=%d]\n" , TreeScale.name , TreeScale.value );
106 printf( "\t[--%s <tree depth>=%d]\n" , TreeDepth.name , TreeDepth.value );
107 printf( "\t[--%s <parallel type>=%d]\n" , ParallelType.name , ParallelType.value );
108 for( size_t i=0 ; i<ThreadPool::ParallelNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ParallelNames[i].c_str() );
109 printf( "\t[--%s <schedue type>=%d]\n" , ScheduleType.name , ScheduleType.value );
110 for( size_t i=0 ; i<ThreadPool::ScheduleNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ScheduleNames[i].c_str() );
111 printf( "\t[--%s <thread chunk size>=%d]\n" , ThreadChunkSize.name , ThreadChunkSize.value );
112 printf( "\t[--%s <iso-value for extraction>=%f]\n" , IsoValue.name , IsoValue.value );
113 printf( "\t[-%s <extraction slab depth>=%d]\n" , IsoSlabDepth.name , IsoSlabDepth.value );
114 printf( "\t[-%s <extraction slab start>=%d]\n" , IsoSlabStart.name , IsoSlabStart.value );
115 printf( "\t[-%s <extraction slab end>=%d]\n" , IsoSlabEnd .name , IsoSlabEnd .value );
116 printf( "\t[--%s <output slice name>]\n" , OutSlice.name );
117 printf( "\t[--%s <output slice depth>]\n" , SliceDepth.name );
118 printf( "\t[--%s <output slice index>]\n" , SliceIndex.name );
119 printf( "\t[--%s]\n" , NonManifold.name );
120 printf( "\t[--%s]\n" , PolygonMesh.name );
121 printf( "\t[--%s]\n" , NonLinearFit.name );
122 printf( "\t[--%s]\n" , FlipOrientation.name );
123 printf( "\t[--%s]\n" , PrimalGrid.name );
124 printf( "\t[--%s]\n" , ASCII.name );
125 printf( "\t[--%s]\n" , Verbose.name );
126 }
127
128 template< typename Real , unsigned int Dim >
129 void WriteGrid( const char *fileName , ConstPointer( Real ) values , unsigned int res , XForm< Real , Dim+1 > voxelToModel , bool verbose , bool normalize=true )
130 {
131 char *ext = GetFileExtension( fileName );
132
133 if( Dim==2 && ImageWriter::ValidExtension( ext ) )
134 {
135 unsigned int totalResolution = 1;
136 for( int d=0 ; d<Dim ; d++ ) totalResolution *= res;
137
138 // Compute average
139 Real avg = 0;
140 std::vector< Real > avgs( ThreadPool::NumThreads() , 0 );
141 ThreadPool::ParallelFor( 0 , totalResolution , [&]( unsigned int thread , size_t i ){ avgs[thread] += values[i]; } );
142 for( unsigned int t=0 ; t<ThreadPool::NumThreads() ; t++ ) avg += avgs[t];
143 avg /= (Real)totalResolution;
144
145 // Compute standard deviation
146 Real std = 0;
147 std::vector< Real > stds( ThreadPool::NumThreads() , 0 );
148 ThreadPool::ParallelFor( 0 , totalResolution , [&]( unsigned int thread , size_t i ){ stds[thread] += ( values[i] - avg ) * ( values[i] - avg ); } );
149 for( unsigned int t=0 ; t<ThreadPool::NumThreads() ; t++ ) std += stds[t];
150 std = (Real)sqrt( std / totalResolution );
151
152 if( verbose )
153 {
154 printf( "Grid to image: [%.2f,%.2f] -> [0,255]\n" , avg - 2*std , avg + 2*std );
155 printf( "Transform:\n" );
156 for( int i=0 ; i<Dim+1 ; i++ )
157 {
158 printf( "\t" );
159 for( int j=0 ; j<Dim+1 ; j++ ) printf( " %f" , voxelToModel(j,i) );
160 printf( "\n" );
161 }
162 }
163
164 unsigned char *pixels = new unsigned char[ totalResolution*3 ];
165 ThreadPool::ParallelFor( 0 , totalResolution , [&]( unsigned int , size_t i )
166 {
167 Real v = (Real)std::min< Real >( (Real)1. , std::max< Real >( (Real)-1. , ( values[i] - avg ) / (2*std ) ) );
168 v = (Real)( ( v + 1. ) / 2. * 256. );
169 unsigned char color = (unsigned char )std::min< Real >( (Real)255. , std::max< Real >( (Real)0. , v ) );
170 for( int c=0 ; c<3 ; c++ ) pixels[i*3+c ] = color;
171 }
172 );
173 ImageWriter::Write( fileName , pixels , res , res , 3 );
174 delete[] pixels;
175 }
176 else if( !strcasecmp( ext , "iso" ) )
177 {
178 FILE *fp = fopen( fileName , "wb" );
179 if( !fp ) MK_THROW( "Failed to open file for writing: " , fileName );
180 int r = (int)res;
181 fwrite( &r , sizeof(int) , 1 , fp );
182 size_t count = 1;
183 for( unsigned int d=0 ; d<Dim ; d++ ) count *= res;
184 fwrite( values , sizeof(Real) , count , fp );
185 fclose( fp );
186 }
187 else
188 {
189 unsigned int _res[Dim];
190 for( int d=0 ; d<Dim ; d++ ) _res[d] = res;
191 RegularGrid< Real , Dim >::Write( fileName , _res , values , voxelToModel );
192 }
193 delete[] ext;
194 }
195 template< unsigned int Dim , class Real , unsigned int FEMSig >
196 void _Execute( const FEMTree< Dim , Real > *tree , XForm< Real , Dim+1 > modelToUnitCube , BinaryStream &stream )
197 {
198 ThreadPool::ParallelizationType= (ThreadPool::ParallelType)ParallelType.value;
199 static const unsigned int Degree = FEMSignature< FEMSig >::Degree;
200 DenseNodeData< Real , IsotropicUIntPack< Dim , FEMSig > > coefficients;
201
202 coefficients.read( stream );
203
204 // Evaluate at the sample positions
205 if( Samples.set )
206 {
207 InputDataStream< Point< Real , Dim > > *pointStream;
208 typedef VertexFactory::PositionFactory< Real , Dim > InFactory;
209 char* ext = GetFileExtension( Samples.value );
210 if ( !strcasecmp( ext , "bpts" ) ) pointStream = new BinaryInputDataStream< InFactory >( Samples.value , InFactory() );
211 else if( !strcasecmp( ext , "ply" ) ) pointStream = new PLYInputDataStream< InFactory >( Samples.value , InFactory() );
212 else pointStream = new ASCIIInputDataStream< InFactory >( Samples.value , InFactory() );
213 delete[] ext;
214 typename FEMTree< Dim , Real >::template MultiThreadedEvaluator< IsotropicUIntPack< Dim , FEMSig > , 0 > evaluator( tree , coefficients );
215 static const unsigned int CHUNK_SIZE = 1024;
216 Point< Real , Dim > points[ CHUNK_SIZE ];
217 Real values[ CHUNK_SIZE ];
218 size_t pointsRead;
219 auto ReadBatch = [&]( void )
220 {
221 size_t c=0;
222 for( size_t i=0 ; i<CHUNK_SIZE ; i++ , c++ ) if( !pointStream->read( points[i] ) ) break;
223 return c;
224 };
225 while( ( pointsRead=ReadBatch() ) )
226 {
227 ThreadPool::ParallelFor( 0 , pointsRead , [&]( unsigned int thread , size_t j )
228 {
229 Point< Real , Dim > p = modelToUnitCube * points[j];
230 bool inBounds = true;
231 for( int d=0 ; d<Dim ; d++ ) if( p[d]<0 || p[d]>1 ) inBounds = false;
232 if( inBounds ) values[j] = evaluator.values( modelToUnitCube * points[j] , thread )[0];
233 else values[j] = (Real)nan( "" );
234 }
235 );
236 for( int j=0 ; j<pointsRead ; j++ ) printf( "%g %g %g\n" , points[j][0] , points[j][1] , values[j] );
237 }
238
239 delete pointStream;
240 }
241
242 // Output the grid
243 if( OutGrid.set )
244 {
245 int res = 0;
246 double t = Time();
247 Pointer( Real ) values = tree->template regularGridEvaluate< true >( coefficients , res , -1 , PrimalGrid.set );
248 if( Verbose.set ) printf( "Got grid: %.2f(s)\n" , Time()-t );
249 XForm< Real , Dim+1 > voxelToUnitCube = XForm< Real , Dim+1 >::Identity();
250 if( PrimalGrid.set ) for( int d=0 ; d<Dim ; d++ ) voxelToUnitCube( d , d ) = (Real)( 1. / (res-1) );
251 else for( int d=0 ; d<Dim ; d++ ) voxelToUnitCube( d , d ) = (Real)( 1. / res ) , voxelToUnitCube( Dim , d ) = (Real)( 0.5 / res );
252 WriteGrid< Real , Dim >( OutGrid.value , values , res , modelToUnitCube.inverse() * voxelToUnitCube , Verbose.set );
253 DeletePointer( values );
254 }
255
256 // Output the tree
257 if( OutTree.set )
258 {
259 DenseNodeData< Real , IsotropicUIntPack< Dim , FEMTrivialSignature > > _coefficients = tree->initDenseNodeData( IsotropicUIntPack< Dim , FEMTrivialSignature >() );
260 ThreadPool::ParallelFor( 0 , _coefficients.size() , [&]( unsigned int , size_t i ){ _coefficients[i] = 0; } );
261
262 if( TreeDepth.value!=-1 )
263 {
264 ThreadPool::ParallelFor
265 (
266 tree->nodesBegin(TreeDepth.value) , tree->nodesEnd(TreeDepth.value) ,
267 [&]( unsigned int , size_t i )
268 {
269 const typename FEMTree< Dim , Real >::FEMTreeNode *node = tree->node( (node_index_type)i );
270 if( tree->isValidFEMNode( IsotropicUIntPack< Dim , FEMTrivialSignature >() , node ) ) _coefficients[ node ] = (Real)i;
271 }
272 );
273 }
274 else
275 {
276 ThreadPool::ParallelFor
277 (
278 tree->nodesBegin(0) , tree->nodesEnd( tree->depth() ) ,
279 [&]( unsigned int , size_t i )
280 {
281 const typename FEMTree< Dim , Real >::FEMTreeNode *node = tree->node( (node_index_type)i );
282 if( tree->isValidFEMNode( IsotropicUIntPack< Dim , FEMTrivialSignature >() , node ) && !tree->isValidFEMNode( IsotropicUIntPack< Dim , FEMTrivialSignature >() , node->children ) )
283 _coefficients[ node ] = (Real)i;
284 }
285 );
286 }
287 int res = 0;
288 double t = Time();
289 Pointer( Real ) values = tree->template regularGridEvaluate< true >( _coefficients , res , -1 , false );
290 if( Verbose.set ) printf( "Got grid: %.2f(s)\n" , Time()-t );
291
292 int _res = res * TreeScale.value + 1;
293 size_t count = 1;
294 for( int d=0 ; d<Dim ; d++ ) count *= _res;
295
296 Pointer( Real ) dValues = NewPointer< Real >( count );
297
298 // In the original indexing, index i corresponds to the position
299 // i -> (i+0.5)/res
300 // In the new indexing, index j corresponds to the position
301 // j -> j/(_res-1)
302 // The two neighbors of index j are:
303 // j0 = j/(_res-1) - 1/(2*scale)
304 // j1 = j/(_res-1) + 1/(2*scale)
305
306 {
307 bool boundary[Dim+1];
308 int idx[Dim] , idx0[Dim] , idx1[Dim];
309 boundary[0] = false;
310
311 auto Index = [&]( const int i[] , unsigned int r )
312 {
313 size_t index = 0;
314 for( int d=Dim-1 ; d>=0 ; d-- ) index = index*r + (size_t)i[d];
315 return index;
316 };
317 auto _Index = [&]( const int i[] , unsigned int r )
318 {
319 size_t index = 0;
320 for( int d=Dim-1 ; d>=0 ; d-- )
321 {
322 std::cout << index << " * " << r << " + " << i[d] << " = ";
323 index = index*r + (size_t)i[d];
324 std::cout <<index << std::endl;
325 }
326 return index;
327 };
328
329 WindowLoop< Dim >::Run
330 (
331 0 , _res ,
332 [&]( int d , int i )
333 {
334 idx [d] = i;
335 idx0[d] = (int)floor( ( (double)i/(_res-1) - 1./(2.*TreeScale.value*res ) ) * res );
336 idx1[d] = (int)floor( ( (double)i/(_res-1) + 1./(2.*TreeScale.value*res ) ) * res );
337 boundary[d+1] = boundary[d] || idx0[d]==-1 || idx1[d]==res;
338 } ,
339 [&]( void )
340 {
341 if( !boundary[Dim] )
342 {
343 Real v1 = values[ Index( idx0 , res ) ];
344 int _idx[Dim];
345 for( int d=0 ; d<Dim ; d++ ) _idx[d] = idx0[d];
346 for( int d=0 ; d<Dim ; d++ )
347 {
348 _idx[d] = idx1[d];
349 Real v2 = values[ Index( _idx , res ) ];
350 _idx[d] = idx0[d];
351 if( v1!=v2 ) boundary[Dim] = true;
352 }
353 }
354 dValues[ Index( idx , _res ) ] = (Real)( boundary[Dim] ? 0 : 1 );
355 }
356 );
357 }
358
359 XForm< Real , Dim+1 > voxelToUnitCube = XForm< Real , Dim+1 >::Identity();
360 if( PrimalGrid.set ) for( int d=0 ; d<Dim ; d++ ) voxelToUnitCube( d , d ) = (Real)( 1. / (res-1) );
361 else for( int d=0 ; d<Dim ; d++ ) voxelToUnitCube( d , d ) = (Real)( 1. / res ) , voxelToUnitCube( Dim , d ) = (Real)( 0.5 / res );
362 WriteGrid< Real , Dim >( OutTree.value , dValues , _res , modelToUnitCube.inverse() * voxelToUnitCube , Verbose.set , false );
363 DeletePointer( values );
364 DeletePointer( dValues );
365 }
366
367 if( OutSlice.set && SliceDepth.set && SliceIndex.set )
368 {
369 using SliceFEMTreeNode = RegularTreeNode< Dim-1 , FEMTreeNodeData , depth_and_offset_type >;
370
371 FEMTree< Dim-1 , Real > *sliceTree = FEMTree< Dim-1 , Real >::template Slice< Degree , 0 >( *tree , SliceDepth.value , SliceIndex.value , true , MEMORY_ALLOCATOR_BLOCK_SIZE );
372
373 DenseNodeData< Real , IsotropicUIntPack< Dim-1 , FEMSig > > sliceCoefficients = sliceTree->initDenseNodeData( IsotropicUIntPack< Dim-1 , FEMSig >() );
374 sliceTree->template slice< 0 , FEMSig >( *tree , 0 , coefficients , sliceCoefficients , SliceDepth.value , SliceIndex.value );
375
376 XForm< Real , Dim > sliceModelToUnitCube;
377 sliceModelToUnitCube( Dim-1 , Dim-1 ) = 1.;
378 for( unsigned int i=0 ; i<(Dim-1) ; i++ )
379 {
380 for( unsigned int j=0 ; j<(Dim-1) ; j++ ) sliceModelToUnitCube(i,j) = modelToUnitCube(i,j);
381 sliceModelToUnitCube(Dim-1,i) = modelToUnitCube(Dim,i);
382 }
383 FILE *fp = fopen( OutSlice.value , "wb" );
384 if( !fp ) MK_THROW( "Failed to open file for writing: " , OutSlice.value );
385 FileStream fs(fp);
386 FEMTree< Dim-1 , Real >::WriteParameter( fs );
387 DenseNodeData< Real , IsotropicUIntPack< Dim-1 , FEMSig > >::WriteSignatures( fs );
388 sliceTree->write( fs , false );
389 fs.write( sliceModelToUnitCube );
390 sliceCoefficients.write( fs );
391 fclose( fp );
392
393 delete sliceTree;
394 }
395
396 // Output the mesh
397 if constexpr( Dim==2 || Dim==3 ) if( OutMesh.set )
398 {
399 double t = Time();
400
401 // A description of the output vertex information
402 using VInfo = Reconstructor::OutputVertexInfo< Real , Dim , false , false >;
403
404 // A factory generating the output vertices
405 using Factory = typename VInfo::Factory;
406 Factory factory = VInfo::GetFactory();
407
408 // A backing stream for the vertices
409 Reconstructor::OutputInputFactoryTypeStream< Real , Dim , Factory , false , true > vertexStream( factory , VInfo::Convert );
410 Reconstructor::OutputInputFaceStream< Dim-1 , false , true > faceStream;
411
412 // Extract the mesh
413 Reconstructor::TransformedOutputLevelSetVertexStream< Real , Dim > _vertexStream( modelToUnitCube.inverse() , vertexStream );
414 if constexpr( Dim==3 ) LevelSetExtractor< Real , Dim >::Extract( IsotropicUIntPack< Dim , FEMSig >() , UIntPack< 0 >() , *tree , ( typename FEMTree< Dim , Real >::template DensityEstimator< 0 >* )NULL , coefficients , IsoValue.value , IsoSlabDepth.value , IsoSlabStart.value , IsoSlabEnd.value , _vertexStream , faceStream , NonLinearFit.set , false , !NonManifold.set , PolygonMesh.set , FlipOrientation.set );
415 else if constexpr( Dim==2 ) LevelSetExtractor< Real , Dim >::Extract( IsotropicUIntPack< Dim , FEMSig >() , UIntPack< 0 >() , *tree , ( typename FEMTree< Dim , Real >::template DensityEstimator< 0 >* )NULL , coefficients , IsoValue.value , _vertexStream , faceStream , NonLinearFit.set , false , FlipOrientation.set );
416
417 if( Verbose.set ) printf( "Got level-set: %.2f(s)\n" , Time()-t );
418 if( Verbose.set ) printf( "Vertices / Faces: %llu / %llu\n" , (unsigned long long)vertexStream.size() , (unsigned long long)faceStream.size() );
419
420 // Write the mesh to a .ply file
421 std::vector< std::string > noComments;
422 PLY::Write< Factory , node_index_type , Real , Dim >( OutMesh.value , factory , vertexStream.size() , faceStream.size() , vertexStream , faceStream , ASCII.set ? PLY_ASCII : PLY_BINARY_NATIVE , noComments );
423 }
424 }
425
426 template< unsigned int Dim , class Real , BoundaryType BType >
427 void Execute( BinaryStream &stream , int degree , FEMTree< Dim , Real > *tree , XForm< Real , Dim+1 > modelToUnitCube )
428 {
429 switch( degree )
430 {
431 case 1: _Execute< Dim , Real , FEMDegreeAndBType< 1 , BType >::Signature >( tree , modelToUnitCube , stream ) ; break;
432 case 2: _Execute< Dim , Real , FEMDegreeAndBType< 2 , BType >::Signature >( tree , modelToUnitCube , stream ) ; break;
433 case 3: _Execute< Dim , Real , FEMDegreeAndBType< 3 , BType >::Signature >( tree , modelToUnitCube , stream ) ; break;
434 case 4: _Execute< Dim , Real , FEMDegreeAndBType< 4 , BType >::Signature >( tree , modelToUnitCube , stream ) ; break;
435 default: MK_THROW( "Only B-Splines of degree 1 - 4 are supported" );
436 }
437 }
438
439 template< unsigned int Dim , class Real >
440 void Execute( BinaryStream &stream , int degree , BoundaryType bType )
441 {
442 XForm< Real , Dim+1 > modelToUnitCube;
443 FEMTree< Dim , Real > tree( stream , MEMORY_ALLOCATOR_BLOCK_SIZE );
444 stream.read( modelToUnitCube );
445
446 if( Verbose.set ) printf( "All Nodes / Active Nodes / Ghost Nodes: %llu / %llu / %llu\n" , (unsigned long long)tree.allNodes() , (unsigned long long)tree.activeNodes() , (unsigned long long)tree.ghostNodes() );
447
448 switch( bType )
449 {
450 case BOUNDARY_FREE: return Execute< Dim , Real , BOUNDARY_FREE >( stream , degree , &tree , modelToUnitCube );
451 case BOUNDARY_NEUMANN: return Execute< Dim , Real , BOUNDARY_NEUMANN >( stream , degree , &tree , modelToUnitCube );
452 case BOUNDARY_DIRICHLET: return Execute< Dim , Real , BOUNDARY_DIRICHLET >( stream , degree , &tree , modelToUnitCube );
453 default: MK_THROW( "Not a valid boundary type: " , bType );
454 }
455 }
456
457 int main( int argc , char* argv[] )
458 {
459 #ifdef ARRAY_DEBUG
460 MK_WARN( "Array debugging enabled" );
461 #endif // ARRAY_DEBUG
462 CmdLineParse( argc-1 , &argv[1] , params );
463 ThreadPool::ChunkSize = ThreadChunkSize.value;
464 ThreadPool::Schedule = (ThreadPool::ScheduleType)ScheduleType.value;
465 if( Verbose.set )
466 {
467 printf( "**************************************************\n" );
468 printf( "**************************************************\n" );
469 printf( "** Running Octree Visualization (Version %s) **\n" , ADAPTIVE_SOLVERS_VERSION );
470 printf( "**************************************************\n" );
471 printf( "**************************************************\n" );
472 }
473
474 if( !In.set )
475 {
476 ShowUsage( argv[0] );
477 return EXIT_FAILURE;
478 }
479 FILE* fp = fopen( In.value , "rb" );
480 if( !fp ) MK_THROW( "Failed to open file for reading: " , In.value );
481 FEMTreeRealType realType ; int degree ; BoundaryType bType;
482 unsigned int dimension;
483 FileStream fs(fp);
484 ReadFEMTreeParameter( fs , realType , dimension );
485 {
486 unsigned int dim = dimension;
487 unsigned int* sigs = ReadDenseNodeDataSignatures( fs , dim );
488 if( dimension!=dim ) MK_THROW( "Octree and node data dimensions don't math: " , dimension , " != " , dim );
489 for( unsigned int d=1 ; d<dim ; d++ ) if( sigs[0]!=sigs[d] ) MK_THROW( "Anisotropic signatures" );
490 degree = FEMSignatureDegree( sigs[0] );
491 bType = FEMSignatureBType( sigs[0] );
492 delete[] sigs;
493 }
494 if( Verbose.set ) printf( "%d-dimension , %s-precision , degree-%d , %s-boundary\n" , dimension , FEMTreeRealNames[ realType ] , degree , BoundaryNames[ bType ] );
495
496 switch( dimension )
497 {
498 case 2:
499 switch( realType )
500 {
501 case FEM_TREE_REAL_FLOAT: Execute< 2 , float >( fs , degree , bType ) ; break;
502 case FEM_TREE_REAL_DOUBLE: Execute< 2 , double >( fs , degree , bType ) ; break;
503 default: MK_THROW( "Unrecognized real type: " , realType );
504 }
505 break;
506 case 3:
507 switch( realType )
508 {
509 case FEM_TREE_REAL_FLOAT: Execute< 3 , float >( fs , degree , bType ) ; break;
510 case FEM_TREE_REAL_DOUBLE: Execute< 3 , double >( fs , degree , bType ) ; break;
511 default: MK_THROW( "Unrecognized real type: " , realType );
512 }
513 break;
514 default: MK_THROW( "Only dimensions 1-4 supported" );
515 }
516
517 fclose( fp );
518 return EXIT_SUCCESS;
519 }