Debian Codegraph @

src/thirdparty/PoissonRecon/PoissonReconServer.cpp

raw
1 /*
2 Copyright (c) 2023, 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 #define BIG_DATA
30 #include "PreProcessor.h"
31
32 #include "Socket.h"
33 #include "PoissonReconClientServer.h"
34 #include "PointPartitionClientServer.h"
35 #include "MergePlyClientServer.h"
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <algorithm>
40 #include "MyMiscellany.h"
41 #include "CmdLineParser.h"
42 #include "Reconstructors.h"
43
44 #define DEFAULT_DIMENSION 3
45
46 using namespace PoissonRecon;
47
48 enum MergeSlabType
49 {
50 NONE ,
51 FUNCTION , // Identical functions across slice
52 TOPOLOGY_AND_FUNCTION , // Identical topologies across slice
53 SEAMLESS , // Merge across the shared slice
54 COUNT
55 };
56
57 const std::string MergeSlabNames[] = { "none" , "function" , "topology" , "seamless" };
58
59 CmdLineParameter< std::string >
60 AddressPrefix( "prefix" ) ,
61 In( "in" ) ,
62 TempDir( "tempDir" ) ,
63 Out( "out" );
64
65 CmdLineParameter< int >
66 ClientCount( "count" ) ,
67 Port( "port" , 0 ) ,
68 Verbose( "verbose" , 0 ) ,
69 #ifdef FAST_COMPILE
70 #else // !FAST_COMPILE
71 Degree( "degree" , Reconstructor::Poisson::DefaultFEMDegree ) ,
72 BType( "bType" , Reconstructor::Poisson::DefaultFEMBoundary ) ,
73 #endif // FAST_COMPILE
74 Iters( "iters" , 8 ) ,
75 BaseVCycles( "vCycles" , 1 ) ,
76 KernelDepth( "kernelDepth" ) ,
77 BaseDepth( "baseDepth" , 5 ) ,
78 SolveDepth( "solveDepth" , -1 ) ,
79 PadSize( "pad" , 4 ) ,
80 BufferSize( "buffer" , BUFFER_IO ) ,
81 Depth( "depth" , 8 ) ,
82 PartitionDepth( "pDepth" , 5 ) ,
83 FilesPerDir( "filesPerDir" , -1 ) ,
84 MaxMemoryGB( "maxMemory" , 0 ) ,
85 PeakMemorySampleMS( "sampleMS" , 10 ) ,
86 ParallelType( "parallel" , 0 ) ,
87 ScheduleType( "schedule" , (int)ThreadPool::Schedule ) ,
88 ThreadChunkSize( "chunkSize" , (int)ThreadPool::ChunkSize ) ,
89 MergeSlabs( "merge" , MergeSlabType::SEAMLESS ) ,
90 AlignmentDir( "alignDir" , -1 );
91
92 CmdLineReadable
93 Performance( "performance" ) ,
94 NoLoadBalance( "noLoadBalance" ) ,
95 Density( "density" ) ,
96 LinearFit( "linearFit" ) ,
97 OutputVoxelGrid( "grid" ) ,
98 OutputBoundarySlices( "boundary" ) ,
99 GridCoordinates( "gridCoordinates" ) ,
100 KeepSeparate( "keepSeparate" ) ,
101 OutputSolution( "solution" ) ,
102 Confidence( "confidence" ) ,
103 ShowDiscontinuity( "showDiscontinuity" );
104
105 CmdLineParameter< float >
106 Scale( "scale" , 1.1f ) ,
107 Width( "width" , 0.f ) ,
108 SamplesPerNode( "samplesPerNode" , 1.5f ) ,
109 DataX( "data" , 32.f ) ,
110 PointWeight( "pointWeight" ) ,
111 TargetValue( "targetValue" , 0.5f ) ,
112 CGSolverAccuracy( "cgAccuracy" , 1e-3f );
113
114 CmdLineReadable* params[] =
115 {
116 &Port , &ClientCount , &AddressPrefix , &Performance , &Verbose ,
117 &In ,
118 &Scale ,
119 &PartitionDepth ,
120 &FilesPerDir ,
121 &TempDir ,
122 &Out ,
123 &KeepSeparate ,
124 #ifdef FAST_COMPILE
125 #else // !FAST_COMPILE
126 &Degree , &BType ,
127 #endif // FAST_COMPILE
128 &Iters , &BaseVCycles , &KernelDepth , &BaseDepth , &PadSize , &BufferSize , &Depth ,
129 &SolveDepth ,
130 &NoLoadBalance , &Density , &LinearFit ,
131 &MergeSlabs ,
132 &Width , &Confidence , &SamplesPerNode , &DataX , &PointWeight , &CGSolverAccuracy ,
133 &TargetValue ,
134 &MaxMemoryGB , &ParallelType , &ScheduleType , &ThreadChunkSize ,
135 &PeakMemorySampleMS ,
136 &OutputVoxelGrid ,
137 &OutputBoundarySlices ,
138 &GridCoordinates ,
139 &OutputSolution ,
140 &AlignmentDir ,
141 &ShowDiscontinuity ,
142 NULL
143 };
144
145 void ShowUsage( char* ex )
146 {
147 printf( "Usage: %s\n" , ex );
148 printf( "\t --%s <input points>\n" , In.name );
149 printf( "\t --%s <networked temporary directory>\n" , TempDir.name );
150 printf( "\t --%s <output polygon mesh (header)>\n" , Out.name );
151 printf( "\t --%s <client count>\n" , ClientCount.name );
152
153 printf( "\t[--%s <preferred address prefix>]\n" , AddressPrefix.name );
154 printf( "\t[--%s <listen port>=%d]\n" , Port.name , Port.value );
155
156 #ifdef FAST_COMPILE
157 #else // !FAST_COMPILE
158 printf( "\t[--%s <b-spline degree>=%d]\n" , Degree.name , Degree.value );
159 printf( "\t[--%s <boundary type>=%d]\n" , BType.name , BType.value );
160 for( int i=0 ; i<BOUNDARY_COUNT ; i++ ) printf( "\t\t%d] %s\n" , i , BoundaryNames[i] );
161 #endif // FAST_COMPILE
162 printf( "\t[--%s <minimum number of samples per node>=%f]\n" , SamplesPerNode.name, SamplesPerNode.value );
163 printf( "\t[--%s <base depth>=%d]\n" , BaseDepth.name , BaseDepth.value );
164 printf( "\t[--%s <max reconstruction depth>=%d]\n" , Depth.name , Depth.value );
165 printf( "\t[--%s <partition depth>=%d]\n" , PartitionDepth.name , PartitionDepth.value );
166 printf( "\t[--%s <kernel depth>]\n" , KernelDepth.name );
167 printf( "\t[--%s <solver depth>]\n" , SolveDepth.name );
168 printf( "\t[--%s <scale factor>=%f]\n" , Scale.name , Scale.value );
169 printf( "\t[--%s <grid width>]\n" , Width.name );
170 printf( "\t[--%s <iterations>=%d]\n" , Iters.name , Iters.value );
171 printf( "\t[--%s <base MG solver v-cycles>=%d]\n" , BaseVCycles.name , BaseVCycles.value );
172 printf( "\t[--%s <cg solver accuracy>=%g]\n" , CGSolverAccuracy.name , CGSolverAccuracy.value );
173 printf( "\t[--%s <target value>=%f]\n" , TargetValue.name , TargetValue.value );
174 printf( "\t[--%s <interpolation weight>=%.3e * <b-spline degree>]\n" , PointWeight.name , Reconstructor::Poisson::WeightMultiplier );
175 printf( "\t[--%s <pull factor>=%f]\n" , DataX.name , DataX.value );
176 printf( "\t[--%s <pad size>=%d]\n" , PadSize.name , PadSize.value );
177 printf( "\t[--%s <buffer size>=%d]\n" , BufferSize.name , BufferSize.value );
178 printf( "\t[--%s <parallel type>=%d]\n" , ParallelType.name , ParallelType.value );
179 for( size_t i=0 ; i<ThreadPool::ParallelNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ParallelNames[i].c_str() );
180 printf( "\t[--%s <schedue type>=%d]\n" , ScheduleType.name , ScheduleType.value );
181 for( size_t i=0 ; i<ThreadPool::ScheduleNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ScheduleNames[i].c_str() );
182 printf( "\t[--%s <thread chunk size>=%d]\n" , ThreadChunkSize.name , ThreadChunkSize.value );
183 printf( "\t[--%s <peak memory sampling rate (ms)>=%d]\n" , PeakMemorySampleMS.name , PeakMemorySampleMS.value );
184 printf( "\t[--%s <maximum memory (in GB)>=%d]\n" , MaxMemoryGB.name , MaxMemoryGB.value );
185 printf( "\t[--%s <slab files per directory>=%u]\n" , FilesPerDir.name , (unsigned int)FilesPerDir.value );
186 printf( "\t[--%s <merge slab type>=%d]\n" , MergeSlabs.name , MergeSlabs.value );
187 for( unsigned int i=0 ; i<MergeSlabType::COUNT ; i++ ) printf( "\t\t%d] %s\n" , (int)i , MergeSlabNames[i].c_str() );
188 printf( "\t[--%s <alignment direction>=%d]\n" , AlignmentDir.name , AlignmentDir.value );
189 printf( "\t[--%s <verbosity>=%d]\n" , Verbose.name , Verbose.value );
190 printf( "\t[--%s]\n" , Confidence.name );
191 printf( "\t[--%s]\n" , NoLoadBalance.name );
192 printf( "\t[--%s]\n" , Density.name );
193 printf( "\t[--%s]\n" , LinearFit.name );
194 printf( "\t[--%s]\n" , OutputVoxelGrid.name );
195 printf( "\t[--%s]\n" , OutputBoundarySlices.name );
196 printf( "\t[--%s]\n" , GridCoordinates.name );
197 printf( "\t[--%s]\n" , OutputSolution.name );
198 printf( "\t[--%s]\n" , ShowDiscontinuity.name );
199 printf( "\t[--%s]\n" , KeepSeparate.name );
200
201 printf( "\t[--%s]\n" , Performance.name );
202 }
203
204 template< typename Real , unsigned int Dim >
205 std::pair< PointPartition::PointSetInfo< Real , Dim > , PointPartition::Partition >
206 Partition
207 (
208 std::vector< Socket > &clientSockets ,
209 const PointPartitionClientServer::ClientPartitionInfo< Real > &clientPartitionInfo ,
210 bool loadBalance ,
211 bool performance
212 )
213 {
214 Timer timer;
215
216 std::pair< PointPartition::PointSetInfo< Real , Dim > , PointPartition::Partition > pointSetInfoAndPartition = PointPartitionClientServer::RunServer< Real , Dim >( clientSockets , clientPartitionInfo , loadBalance );
217 unsigned int peakMem = 0;
218 for( unsigned int c=0 ; c<clientSockets.size() ; c++ )
219 {
220 unsigned int _peakMem;
221 SocketStream( clientSockets[c] ).read( _peakMem );
222 peakMem = std::max< unsigned int >( peakMem , _peakMem );
223 }
224
225 if( performance )
226 {
227 StreamFloatPrecision sfp( std::cout , 2 );
228 std::cout << "Partition performance:" << std::endl;
229 std::cout << "\tPeak client memory: " << peakMem << " (MB)" << std::endl;
230 std::cout << "\tPeak server memory: " << MemoryInfo::PeakMemoryUsageMB() << " (MB)" << std::endl;
231 std::cout << "\tServer Time: " << timer.wallTime() << " (s)" << std::endl;
232 }
233 return pointSetInfoAndPartition;
234 }
235
236 template< typename Real , unsigned int Dim , BoundaryType BType , unsigned int Degree >
237 std::vector< unsigned int >
238 Reconstruct
239 (
240 const PointPartition::PointSetInfo< Real , Dim > &pointSetInfo ,
241 const PointPartition::Partition &pointPartition ,
242 std::vector< Socket > &clientSockets ,
243 const PoissonReconClientServer::ClientReconstructionInfo< Real , Dim > &clientReconInfo
244 )
245 {
246 Timer timer;
247
248 // Clean up files if they were not propertly cleaned up before.
249 for( unsigned int i=0 ; i<clientSockets.size() ; i++ ) PoissonReconClientServer::ClientServerStream< false >::Reset( i , clientReconInfo );
250
251 std::vector< unsigned int > sharedVertexCounts = PoissonReconClientServer::RunServer< Real , Dim , BType , Degree >( pointSetInfo , pointPartition , clientSockets , clientReconInfo , BaseVCycles.value , PeakMemorySampleMS.value<0 ? 0 : PeakMemorySampleMS.value , ShowDiscontinuity.set , OutputBoundarySlices.set );
252
253 unsigned int peakMem = 0;
254 for( unsigned int i=0 ; i<clientSockets.size() ; i++ )
255 {
256 unsigned int _peakMem;
257 SocketStream( clientSockets[i] ).read( _peakMem );
258 peakMem = std::max< unsigned int >( peakMem , _peakMem );
259 }
260
261 if( Performance.set )
262 {
263 StreamFloatPrecision sfp( std::cout , 2 );
264 std::cout << "Reconstruction performance:" << std::endl;
265 std::cout << "\tPeak client memory: " << peakMem << " (MB)" << std::endl;
266 std::cout << "\tPeak server memory: " << MemoryInfo::PeakMemoryUsageMB() << " (MB)" << std::endl;
267 std::cout << "\tServer Time: " << timer.wallTime() << " (s)" << std::endl;
268 }
269
270 return sharedVertexCounts;
271 }
272
273
274 #ifdef FAST_COMPILE
275 #else // !FAST_COMPILE
276 template< typename Real , unsigned int Dim , BoundaryType BType >
277 std::vector< unsigned int > Reconstruct( unsigned int degree , const PointPartition::PointSetInfo< Real , Dim > &pointSetInfo , const PointPartition::Partition &partition , std::vector< Socket > clientSockets , const PoissonReconClientServer::ClientReconstructionInfo< Real , Dim > &clientReconInfo )
278 {
279 switch( degree )
280 {
281 case 1: return Reconstruct< Real , Dim , BType , 1 >( pointSetInfo , partition , clientSockets , clientReconInfo );
282 case 2: return Reconstruct< Real , Dim , BType , 2 >( pointSetInfo , partition , clientSockets , clientReconInfo );
283 default: MK_THROW( "Only B-Splines of degree 1 - 2 are supported" );
284 }
285 return std::vector< unsigned int >();
286 }
287
288 template< typename Real , unsigned int Dim >
289 std::vector< unsigned int > Reconstruct( BoundaryType bType , unsigned int degree , const PointPartition::PointSetInfo< Real , Dim > &pointSetInfo , const PointPartition::Partition &partition , std::vector< Socket > clientSockets , const PoissonReconClientServer::ClientReconstructionInfo< Real , Dim > &clientReconInfo )
290 {
291 for( unsigned int i=0 ; i<clientSockets.size() ; i++ )
292 {
293 SocketStream( clientSockets[i] ).write( bType );
294 SocketStream( clientSockets[i] ).write( degree );
295 }
296 switch( bType )
297 {
298 case BOUNDARY_FREE: return Reconstruct< Real , Dim , BOUNDARY_FREE >( degree , pointSetInfo , partition , clientSockets , clientReconInfo );
299 case BOUNDARY_NEUMANN: return Reconstruct< Real , Dim , BOUNDARY_NEUMANN >( degree , pointSetInfo , partition , clientSockets , clientReconInfo );
300 case BOUNDARY_DIRICHLET: return Reconstruct< Real , Dim , BOUNDARY_DIRICHLET >( degree , pointSetInfo , partition , clientSockets , clientReconInfo );
301 default: MK_THROW( "Not a valid boundary type: " , bType );
302 }
303 return std::vector< unsigned int >();
304 }
305 #endif // FAST_COMPILE
306
307 template< typename Real , unsigned int Dim>
308 void Merge
309 (
310 const std::vector< unsigned int > &sharedVertexCounts ,
311 std::string header ,
312 std::vector< Socket > &clientSockets ,
313 const MergePlyClientServer::ClientMergePlyInfo &clientMergePlyInfo ,
314 const std::pair< PointPartition::PointSetInfo< Real , Dim > , PointPartition::Partition > &pointSetInfoAndPartition
315 )
316 {
317 Timer timer;
318
319 std::function< std::vector< std::string > ( unsigned int ) > commentFunctor = [&]( unsigned int partition )
320 {
321 if( partition==-1 ) return std::vector< std::string >();
322 else
323 {
324 Real res = (Real)( 1<<PartitionDepth.value );
325 std::pair< unsigned int , unsigned int > range = pointSetInfoAndPartition.second.range( partition );
326 Point< Real , Dim > axis;
327 Real offset = pointSetInfoAndPartition.first.modelToUnitCube( Dim , Dim-1 );
328 for( unsigned int d=0 ; d<Dim ; d++ ) axis[d] = pointSetInfoAndPartition.first.modelToUnitCube( d , Dim-1 );
329
330 std::vector< std::string > comments( 1 );
331 std::stringstream sStream;
332
333 Point< Real , Dim+1 > front , back;
334 for( unsigned int d=0 ; d<Dim ; d++ )
335 {
336 front[d] = -axis[d];
337 back[d] = axis[d];
338 }
339 front[Dim] = (range.first/res)-offset;
340 back[Dim] = offset-(range.second/res);
341 char frontStr[ 1024 ] , backStr[ 1024 ];
342 CmdLineType< Point< Real , Dim+1 > >::WriteValue( front , frontStr );
343 CmdLineType< Point< Real , Dim+1 > >::WriteValue( back , backStr );
344 sStream << "Partition: " << std::string( frontStr ) << " " << std::string( backStr );
345
346 comments[0] = sStream.str();
347 return comments;
348 }
349 };
350
351 MergePlyClientServer::RunServer< Real , Dim >( TempDir.value , TempDir.value , header , Out.value , clientSockets , sharedVertexCounts , clientMergePlyInfo , PeakMemorySampleMS.value , commentFunctor );
352
353 unsigned int peakMem = 0;
354 for( unsigned int i=0 ; i<clientSockets.size() ; i++ )
355 {
356 unsigned int _peakMem;
357 SocketStream( clientSockets[i] ).read( _peakMem );
358 peakMem = std::max< unsigned int >( peakMem , _peakMem );
359 }
360
361 if( Performance.set )
362 {
363 StreamFloatPrecision sfp( std::cout , 2 );
364 std::cout << "Merge performance:" << std::endl;
365 std::cout << "\tPeak client memory: " << peakMem << " (MB)" << std::endl;
366 std::cout << "\tPeak server memory: " << MemoryInfo::PeakMemoryUsageMB() << " (MB)" << std::endl;
367 std::cout << "\tServer Time: " << timer.wallTime() << " (s)" << std::endl;
368 }
369 }
370
371 int main( int argc , char* argv[] )
372 {
373 #ifdef ARRAY_DEBUG
374 MK_WARN( "Array debugging enabled" );
375 #endif // ARRAY_DEBUG
376 #ifdef USE_DOUBLE
377 typedef double Real;
378 #else // !USE_DOUBLE
379 typedef float Real;
380 #endif // USE_DOUBLE
381 static const unsigned int Dim = DEFAULT_DIMENSION;
382
383 CmdLineParse( argc-1 , &argv[1] , params );
384
385 if( !In.set || !TempDir.set || !Out.set || !ClientCount.set )
386 {
387 ShowUsage( argv[0] );
388 return 0;
389 }
390 if( PadSize.value<0 ) MK_THROW( "Padding size cannot be negative" );
391
392 if( Verbose.value>1 )
393 {
394 std::cout << "***********************************************************" << std::endl;
395 std::cout << "***********************************************************" << std::endl;
396 std::cout << "** Running Poisson Reconstruction Server (Version " << ADAPTIVE_SOLVERS_VERSION << ") **" << std::endl;
397 std::cout << "***********************************************************" << std::endl;
398 std::cout << "***********************************************************" << std::endl;
399 }
400
401 #ifdef FAST_COMPILE
402 if( !PointWeight.set ) PointWeight.value = Reconstructor::Poisson::WeightMultiplier * Reconstructor::Poisson::DefaultFEMDegree;
403 #else // !FAST_COMPILE
404 if( !PointWeight.set ) PointWeight.value = Reconstructor::Poisson::WeightMultiplier * Degree.value;
405 #endif // FAST_COMPILE
406
407 if( Depth.set && Width.value>0 )
408 {
409 MK_WARN( "Both --" , Depth.name , " and --" , Width.name , " set, ignoring --" , Width.name );
410 Width.value = 0;
411 }
412
413 if( MaxMemoryGB.value>0 ) SetPeakMemoryMB( MaxMemoryGB.value<<10 );
414 ThreadPool::ChunkSize = ThreadChunkSize.value;
415 ThreadPool::Schedule = (ThreadPool::ScheduleType)ScheduleType.value;
416 ThreadPool::ParallelizationType= (ThreadPool::ParallelType)ParallelType.value;
417 std::string header;
418
419 // Create the connections to the clients
420 std::vector< Socket > clientSockets( ClientCount.value );
421 {
422 int port = Port.value;
423
424 char address[512];
425 GetHostAddress( address , AddressPrefix.value.c_str() );
426
427 // Create a listening SOCKET for connecting to server
428 AcceptorSocket listenSocket = GetListenSocket( port );
429 if( listenSocket == _INVALID_ACCEPTOR_SOCKET_ ) MK_THROW( "Could not create listener socket" );
430 std::cout << "Server Address: " << address << ":" << port << std::endl;
431 {
432 std::stringstream ss;
433 ss << "PR_" << port;
434 header = ss.str();
435 }
436
437 // Establish a connection to the clients
438 for( unsigned int i=0 ; i<(unsigned int)ClientCount.value ; i++ )
439 {
440 clientSockets[i] = AcceptSocket( listenSocket );
441 if( Verbose.value>1 ) std::cout << "Connected to process: " << (i+1) << " / " << ClientCount.value << std::endl;
442 }
443 CloseAcceptorSocket( listenSocket );
444 }
445 std::vector< unsigned int > sharedVertexCounts;
446
447
448 std::pair< PointPartition::PointSetInfo< Real , Dim > , PointPartition::Partition > pointSetInfoAndPartition;
449
450 // Get the partitioned points
451 {
452 PointPartition::CreatePointSlabDirs( PointPartition::FileDir( TempDir.value , header ) , 1<<PartitionDepth.value , FilesPerDir.value );
453 PointPartitionClientServer::ClientPartitionInfo< Real > clientPartitionInfo;
454 clientPartitionInfo.in = In.value;
455 clientPartitionInfo.tempDir = TempDir.value;
456 clientPartitionInfo.outDir = TempDir.value;
457 clientPartitionInfo.outHeader = header;
458 clientPartitionInfo.slabs = 1<<PartitionDepth.value;
459 clientPartitionInfo.filesPerDir = FilesPerDir.value;
460 clientPartitionInfo.bufferSize = BufferSize.value;
461 clientPartitionInfo.scale = Scale.value;
462 clientPartitionInfo.sliceDir = AlignmentDir.value;
463 clientPartitionInfo.verbose = Verbose.value>1;
464 pointSetInfoAndPartition = Partition< Real , Dim >( clientSockets , clientPartitionInfo , !NoLoadBalance.set , Performance.set );
465 }
466
467 // Reconstruct the slabs
468 {
469 if( Width.value>0 )
470 {
471 XForm< Real , Dim > unitCubeToModel = pointSetInfoAndPartition.first.modelToUnitCube.inverse();
472
473 Real maxScale = 0;
474 for( unsigned int i=0 ; i<Dim ; i++ )
475 {
476 Real l2 = 0;
477 for( unsigned int j=0 ; j<Dim ; j++ ) l2 += unitCubeToModel(i,j) * unitCubeToModel(i,j);
478 if( l2>maxScale ) maxScale = l2;
479 }
480 maxScale = sqrt( maxScale );
481 Depth.value = (unsigned int)ceil( std::max< double >( 0. , log( maxScale/Width.value )/log(2.) ) );
482 }
483 PoissonReconClientServer::ClientReconstructionInfo< Real , Dim > clientReconInfo;
484 clientReconInfo.inDir = TempDir.value;
485 clientReconInfo.tempDir = TempDir.value;
486 clientReconInfo.outDir = TempDir.value;
487 clientReconInfo.header = header;
488 clientReconInfo.bufferSize = BufferSize.value;
489 clientReconInfo.iters = Iters.value;
490 clientReconInfo.pointWeight = PointWeight.value;
491 clientReconInfo.kernelDepth = KernelDepth.value;
492 clientReconInfo.samplesPerNode = SamplesPerNode.value;
493 clientReconInfo.dataX = DataX.value;
494 clientReconInfo.density = Density.set;
495 clientReconInfo.linearFit = LinearFit.set;
496 clientReconInfo.confidence = Confidence.set;
497 switch( MergeSlabs.value )
498 {
499 case MergeSlabType::NONE: clientReconInfo.mergeType = PoissonReconClientServer::ClientReconstructionInfo< Real , Dim >::MergeType::NONE ; break;
500 case MergeSlabType::FUNCTION: clientReconInfo.mergeType = PoissonReconClientServer::ClientReconstructionInfo< Real , Dim >::MergeType::FUNCTION ; break;
501 default: clientReconInfo.mergeType = PoissonReconClientServer::ClientReconstructionInfo< Real , Dim >::MergeType::TOPOLOGY_AND_FUNCTION;
502 }
503 clientReconInfo.ouputVoxelGrid = OutputVoxelGrid.set;
504 clientReconInfo.targetValue = TargetValue.value;
505 clientReconInfo.outputSolution = OutputSolution.set;
506 clientReconInfo.gridCoordinates = GridCoordinates.set;
507 clientReconInfo.verbose = Verbose.value;
508 clientReconInfo.filesPerDir = FilesPerDir.value;
509 clientReconInfo.padSize = PadSize.value;
510
511 clientReconInfo.reconstructionDepth = Depth.value;
512 clientReconInfo.sharedDepth = 0;
513 while( ((size_t)1<<clientReconInfo.sharedDepth) < pointSetInfoAndPartition.first.pointsPerSlab.size() ) clientReconInfo.sharedDepth++;
514 if( ((size_t)1<<clientReconInfo.sharedDepth)!=pointSetInfoAndPartition.first.pointsPerSlab.size() ) MK_THROW( "Number of point slabs is not a power of two: " , pointSetInfoAndPartition.first.pointsPerSlab.size() );
515 clientReconInfo.baseDepth = BaseDepth.value;
516
517 if( clientReconInfo.pointWeight<0 ) MK_THROW( "Expected non-negative point-weight" );
518
519 if( clientReconInfo.sharedDepth>clientReconInfo.reconstructionDepth ) MK_THROW( "Slab depth cannot exceed reconstruction depth: " , clientReconInfo.sharedDepth , " <= " , clientReconInfo.reconstructionDepth );
520 if( clientReconInfo.baseDepth>clientReconInfo.sharedDepth )
521 {
522 if( BaseDepth.set ) MK_THROW( "Base depth cannot exceed shared depth: " , clientReconInfo.baseDepth , " <=" , clientReconInfo.sharedDepth );
523 else clientReconInfo.baseDepth = clientReconInfo.sharedDepth;
524 }
525 if( !KernelDepth.set ) KernelDepth.value = clientReconInfo.reconstructionDepth-2;
526 clientReconInfo.kernelDepth = KernelDepth.value;
527
528 if( clientReconInfo.kernelDepth>clientReconInfo.reconstructionDepth )
529 {
530 MK_WARN( "Kernel depth should not exceed depth: " , clientReconInfo.kernelDepth , " <= " , clientReconInfo.reconstructionDepth );
531 clientReconInfo.kernelDepth = clientReconInfo.reconstructionDepth;
532 }
533
534 clientReconInfo.solveDepth = ( SolveDepth.set && SolveDepth.value!=-1 ) ? SolveDepth.value : clientReconInfo.reconstructionDepth;
535 if( clientReconInfo.solveDepth>clientReconInfo.reconstructionDepth )
536 {
537 MK_WARN( "Solve depth cannot exceed reconstruction depth: " , clientReconInfo.solveDepth , " <= " , clientReconInfo.reconstructionDepth );
538 clientReconInfo.solveDepth = clientReconInfo.reconstructionDepth;
539 }
540 if( clientReconInfo.solveDepth<clientReconInfo.baseDepth )
541 {
542 MK_WARN( "Solve depth cannot be smaller than base depth: " , clientReconInfo.solveDepth , " >= " , clientReconInfo.baseDepth );
543 clientReconInfo.solveDepth = clientReconInfo.baseDepth;
544 }
545 #ifdef FAST_COMPILE
546 sharedVertexCounts = Reconstruct< Real , Dim , Reconstructor::Poisson::DefaultFEMBoundary , Reconstructor::Poisson::DefaultFEMDegree >( pointSetInfoAndPartition.first , pointSetInfoAndPartition.second , clientSockets , clientReconInfo );
547 #else // !FAST_COMPILE
548 sharedVertexCounts = Reconstruct< Real , Dim >( (BoundaryType)BType.value , Degree.value , pointSetInfoAndPartition.first , pointSetInfoAndPartition.second , clientSockets , clientReconInfo );
549 #endif // FAST_COMPILE
550 }
551
552 if constexpr( Dim==3 ) if( Verbose.value>1 && ( MergeSlabs.value==MergeSlabType::SEAMLESS || MergeSlabs.value==MergeSlabType::TOPOLOGY_AND_FUNCTION ) )
553 for( unsigned int i=0 ; i<sharedVertexCounts.size() ; i++ ) std::cout << "Vertices[" << (i+1) << "] " << sharedVertexCounts[i] << std::endl;
554
555 PointPartition::RemovePointSlabDirs( PointPartition::FileDir( TempDir.value , header ) );
556
557 if constexpr( Dim==3 )
558 {
559 if( MergeSlabs.value!=MergeSlabType::SEAMLESS ) for( unsigned int i=0 ; i<sharedVertexCounts.size() ; i++ ) sharedVertexCounts[i] = 0;
560 MergePlyClientServer::ClientMergePlyInfo clientMergePlyInfo;
561 if( Density.set )
562 {
563 VertexFactory::ValueFactory< Real > vFactory;
564 for( unsigned int i=0 ; i<vFactory.plyWriteNum() ; i++ ) clientMergePlyInfo.auxProperties.push_back( vFactory.plyStaticWriteProperty(i) );
565 for( unsigned int i=0 ; i<pointSetInfoAndPartition.first.auxiliaryProperties.size() ; i++ ) clientMergePlyInfo.auxProperties.push_back( pointSetInfoAndPartition.first.auxiliaryProperties[i] );
566 }
567 else clientMergePlyInfo.auxProperties = pointSetInfoAndPartition.first.auxiliaryProperties;
568 clientMergePlyInfo.bufferSize = BufferSize.value;
569 clientMergePlyInfo.keepSeparate = KeepSeparate.set;
570 clientMergePlyInfo.verbose = Verbose.value!=0;
571
572 Merge< Real , Dim >( sharedVertexCounts , header , clientSockets , clientMergePlyInfo , pointSetInfoAndPartition );
573
574 auto InFile = [&]( unsigned int idx )
575 {
576 std::stringstream ss;
577 ss << header << "." << idx << ".ply";
578 return PointPartition::FileDir( TempDir.value , ss.str() );
579 };
580
581 for( unsigned int i=0 ; i<clientSockets.size() ; i++ )
582 {
583 std::string fileName = InFile(i);
584 std::remove( fileName.c_str() );
585 }
586 }
587
588 for( unsigned int i=0 ; i<clientSockets.size() ; i++ ) CloseSocket( clientSockets[i] );
589
590 if( KeepSeparate.set && Verbose.value>=1 )
591 {
592 Real res = (Real)( 1<<PartitionDepth.value );
593 Point< Real , Dim > axis;
594 Real offset = pointSetInfoAndPartition.first.modelToUnitCube( Dim , Dim-1 );
595 for( unsigned int d=0 ; d<Dim ; d++ ) axis[d] = pointSetInfoAndPartition.first.modelToUnitCube( d , Dim-1 );
596
597 Point< Real , Dim+1 > front , back;
598 for( unsigned int d=0 ; d<Dim ; d++ )
599 {
600 front[d] = -axis[d];
601 back[d] = axis[d];
602 }
603 std::cout << "Partition Axis: " << axis << std::endl;
604 std::cout << "Partitions:" << std::endl;
605 for( unsigned int i=0 ; i<pointSetInfoAndPartition.second.partitions() ; i++ )
606 {
607 std::pair< unsigned int , unsigned int > range = pointSetInfoAndPartition.second.range( i );
608 front[Dim] = (range.first/res)-offset;
609 back[Dim] = offset-(range.second/res);
610 char frontStr[ 1024 ] , backStr[ 1024 ];
611 CmdLineType< Point< Real , Dim+1 > >::WriteValue( front , frontStr );
612 CmdLineType< Point< Real , Dim+1 > >::WriteValue( back , backStr );
613 std::cout << "\t[ " << offset-(range.first/res) << " , " << offset-(range.second/res) << " ] ->";
614 std::cout << std::string( frontStr ) << " " << std::string( backStr ) << std::endl;
615 }
616 }
617
618 return EXIT_SUCCESS;
619 }