| 1 |
/* |
| 2 |
Copyright (c) 2022, Michael Kazhdan and Matthew Bolitho |
| 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 |
#ifndef RECONSTRUCTORS_STREAMS_INCLUDED |
| 30 |
#define RECONSTRUCTORS_STREAMS_INCLUDED |
| 31 |
|
| 32 |
#include "FEMTree.h" |
| 33 |
#include "MyExceptions.h" |
| 34 |
#include "Array.h" |
| 35 |
|
| 36 |
namespace PoissonRecon |
| 37 |
{ |
| 38 |
namespace Reconstructor |
| 39 |
{ |
| 40 |
template< typename Real , unsigned int Dim > using Position = Point< Real , Dim >; |
| 41 |
template< typename Real , unsigned int Dim > using Normal = Point< Real , Dim >; |
| 42 |
template< typename Real , unsigned int Dim > using Gradient = Point< Real , Dim >; |
| 43 |
template< typename Real > using Weight = Real; |
| 44 |
template< typename Real > using Value = Real; |
| 45 |
|
| 46 |
//////////////////////// |
| 47 |
// Input stream types // |
| 48 |
//////////////////////// |
| 49 |
|
| 50 |
template< typename Real , unsigned int Dim , typename ... Data > using InputSampleStream = InputDataStream< Point< Real , Dim > , Data ... >; |
| 51 |
template< typename Real , unsigned int Dim , typename ... Data > struct TransformedInputSampleStream; |
| 52 |
|
| 53 |
template< typename Real , unsigned int Dim , typename ... Data > using InputOrientedSampleStream = InputDataStream< Position< Real , Dim > , Normal< Real , Dim > , Data ... >; |
| 54 |
template< typename Real , unsigned int Dim , typename ... Data > struct TransformedInputOrientedSampleStream; |
| 55 |
|
| 56 |
template< typename Real , unsigned int Dim , typename ... Data > using InputValuedSampleStream = InputSampleStream< Real , Dim , Value< Real > , Data ... >; |
| 57 |
template< typename Real , unsigned int Dim , typename ... Data > using TransformedInputValuedSampleStream = TransformedInputSampleStream< Real , Dim , Value< Real > , Data ... >; |
| 58 |
|
| 59 |
|
| 60 |
///////////////////////// |
| 61 |
// Output stream types // |
| 62 |
///////////////////////// |
| 63 |
|
| 64 |
template< typename Real , unsigned int Dim , typename ... Data > using OutputLevelSetVertexStream = OutputDataStream< Position< Real , Dim > , Gradient< Real , Dim > , Weight< Real > , Data ... >; |
| 65 |
template< typename Real , unsigned int Dim , typename ... Data > struct TransformedOutputLevelSetVertexStream; |
| 66 |
|
| 67 |
////////////////// |
| 68 |
// Face streams // |
| 69 |
////////////////// |
| 70 |
template< unsigned int FaceDim , typename T=node_index_type > using Face = std::conditional_t< FaceDim==2 , std::vector< T > , std::conditional_t< FaceDim==1 , std::pair< T , T > , void * > >; |
| 71 |
template< unsigned int FaceDim > using InputFaceStream = InputDataStream< Face< FaceDim > >; |
| 72 |
template< unsigned int FaceDim > using OutputFaceStream = OutputDataStream< Face< FaceDim > >; |
| 73 |
|
| 74 |
////////////////////////////////////////////// |
| 75 |
// Information about the output vertex type // |
| 76 |
////////////////////////////////////////////// |
| 77 |
template< typename Real , unsigned int Dim , bool HasGradients , bool HasDensity , typename ... AxuDataFactories > struct OutputVertexInfo; |
| 78 |
|
| 79 |
////////////////////////////////////////// |
| 80 |
// Transformed Input Sample Data Stream // |
| 81 |
////////////////////////////////////////// |
| 82 |
template< typename Real , unsigned int Dim , typename ... Data > |
| 83 |
struct TransformedInputSampleStream : public InputSampleStream< Real , Dim , Data ... > |
| 84 |
{ |
| 85 |
// A constructor initialized with the transformation to be applied to the samples, and a sample stream |
| 86 |
TransformedInputSampleStream( XForm< Real , Dim+1 > xForm , InputSampleStream< Real , Dim , Data ... > &stream ) : _stream(stream) , _xForm(xForm) {} |
| 87 |
|
| 88 |
// Functionality to reset the stream to the start |
| 89 |
void reset( void ){ _stream.reset(); } |
| 90 |
|
| 91 |
// Functionality to extract the next position/normal pair. |
| 92 |
// The method returns true if there was another point in the stream to read, and false otherwise |
| 93 |
bool read( Position< Real , Dim > &p , Data& ... d ) |
| 94 |
{ |
| 95 |
if( !_stream.read( p , d... ) ) return false; |
| 96 |
p = _xForm * p; |
| 97 |
return true; |
| 98 |
} |
| 99 |
bool read( unsigned int thread , Position< Real , Dim > &p , Data& ... d ) |
| 100 |
{ |
| 101 |
if( !_stream.read( thread , p , d... ) ) return false; |
| 102 |
p = _xForm * p; |
| 103 |
return true; |
| 104 |
} |
| 105 |
|
| 106 |
protected: |
| 107 |
// A reference to the underlying stream |
| 108 |
InputSampleStream< Real , Dim , Data ... > &_stream; |
| 109 |
|
| 110 |
// The affine transformation to be applied to the positions |
| 111 |
XForm< Real , Dim+1 > _xForm; |
| 112 |
}; |
| 113 |
|
| 114 |
////////////////////////////////////////////////// |
| 115 |
// Transformed Input Oriente Sample Data Stream // |
| 116 |
////////////////////////////////////////////////// |
| 117 |
template< typename Real , unsigned int Dim , typename ... Data > |
| 118 |
struct TransformedInputOrientedSampleStream : public InputOrientedSampleStream< Real , Dim , Data ... > |
| 119 |
{ |
| 120 |
// A constructor initialized with the transformation to be applied to the samples, and a sample stream |
| 121 |
TransformedInputOrientedSampleStream( XForm< Real , Dim+1 > xForm , InputOrientedSampleStream< Real , Dim , Data ... > &stream ) : _stream(stream) , _positionXForm(xForm) |
| 122 |
{ |
| 123 |
_normalXForm = XForm< Real , Dim > ( xForm ).inverse().transpose() * (Real)pow( fabs( xForm.determinant() ) , 1./Dim ); |
| 124 |
} |
| 125 |
|
| 126 |
// Functionality to reset the stream to the start |
| 127 |
void reset( void ){ _stream.reset(); } |
| 128 |
|
| 129 |
// Functionality to extract the next position/normal pair. |
| 130 |
// The method returns true if there was another point in the stream to read, and false otherwise |
| 131 |
bool read( Position< Real , Dim > &p , Normal< Real , Dim > &n , Data& ... d ) |
| 132 |
{ |
| 133 |
if( !_stream.read( p , n , d... ) ) return false; |
| 134 |
p = _positionXForm * p , n = _normalXForm * n; |
| 135 |
return true; |
| 136 |
} |
| 137 |
bool read( unsigned int thread , Position< Real , Dim > &p , Normal< Real , Dim > &n , Data& ... d ) |
| 138 |
{ |
| 139 |
if( !_stream.read( thread , p , n , d... ) ) return false; |
| 140 |
p = _positionXForm * p , n = _normalXForm * n; |
| 141 |
return true; |
| 142 |
} |
| 143 |
|
| 144 |
protected: |
| 145 |
// A reference to the underlying stream |
| 146 |
InputOrientedSampleStream< Real , Dim , Data ... > &_stream; |
| 147 |
|
| 148 |
// The affine transformation to be applied to the positions |
| 149 |
XForm< Real , Dim+1 > _positionXForm; |
| 150 |
|
| 151 |
// The linear transformation to be applied to the normals |
| 152 |
XForm< Real , Dim > _normalXForm; |
| 153 |
}; |
| 154 |
|
| 155 |
////////////////////////////////////// |
| 156 |
// Transformed Output Vertex Stream // |
| 157 |
////////////////////////////////////// |
| 158 |
template< typename Real , unsigned int Dim , typename ... Data > |
| 159 |
struct TransformedOutputLevelSetVertexStream : public OutputLevelSetVertexStream< Real , Dim , Data ... > |
| 160 |
{ |
| 161 |
// A constructor initialized with the transformation to be applied to the samples, and a sample stream |
| 162 |
TransformedOutputLevelSetVertexStream( XForm< Real , Dim+1 > xForm , OutputLevelSetVertexStream< Real , Dim , Data ... > &stream ) : _stream(stream) , _positionXForm(xForm) |
| 163 |
{ |
| 164 |
_gradientXForm = XForm< Real , Dim > ( xForm ).inverse().transpose() * (Real)pow( xForm.determinant() , 1./Dim ); |
| 165 |
} |
| 166 |
|
| 167 |
// Need to write the union to ensure that the counter gets set |
| 168 |
size_t write( const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > &w , const Data& ... d ){ return _stream.write( _positionXForm * p , _gradientXForm * g , w , d... ); } |
| 169 |
size_t write( unsigned int thread , const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > &w , const Data& ... d ){ return _stream.write( thread , _positionXForm * p , _gradientXForm * g , w , d... ); } |
| 170 |
size_t size( void ) const { return _stream.size(); } |
| 171 |
|
| 172 |
protected: |
| 173 |
// A reference to the underlying stream |
| 174 |
OutputLevelSetVertexStream< Real , Dim , Data ... > &_stream; |
| 175 |
|
| 176 |
// The affine transformation to be applied to the positions |
| 177 |
XForm< Real , Dim+1 > _positionXForm; |
| 178 |
|
| 179 |
// The linear transformation to be applied to the normals |
| 180 |
XForm< Real , Dim > _gradientXForm; |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
////////////////////////////////// |
| 185 |
// File-backed streaming memory // |
| 186 |
////////////////////////////////// |
| 187 |
class FileBackedReadWriteStream |
| 188 |
{ |
| 189 |
public: |
| 190 |
struct FileDescription |
| 191 |
{ |
| 192 |
FILE *fp; |
| 193 |
|
| 194 |
FileDescription( FILE *fp ) : fp(fp) , _closeFile(false) |
| 195 |
{ |
| 196 |
if( !this->fp ) |
| 197 |
{ |
| 198 |
this->fp = std::tmpfile(); |
| 199 |
_closeFile = true; |
| 200 |
if( !this->fp ) MK_THROW( "Failed to open temporary file" ); |
| 201 |
} |
| 202 |
} |
| 203 |
~FileDescription( void ){ if( _closeFile ) fclose(fp); } |
| 204 |
protected: |
| 205 |
#ifdef SHOW_WARNINGS |
| 206 |
#pragma message( "[WARNING] Probably can let the system handle closing the file" ) |
| 207 |
#endif // SHOW_WARNINGS |
| 208 |
bool _closeFile; |
| 209 |
}; |
| 210 |
|
| 211 |
FileBackedReadWriteStream( FILE *fp ) : _fd(fp) {} |
| 212 |
bool write( ConstPointer(char) data , size_t size ){ return fwrite( data , sizeof(char) , size , _fd.fp )==size; } |
| 213 |
bool read( Pointer(char) data , size_t size ){ return fread( data , sizeof(char) , size , _fd.fp )==size; } |
| 214 |
void reset( void ){ fseek( _fd.fp , 0 , SEEK_SET ); } |
| 215 |
protected: |
| 216 |
FileDescription _fd; |
| 217 |
}; |
| 218 |
|
| 219 |
|
| 220 |
////////////////////////////////////////////////////////////////////////////// |
| 221 |
// Output and the input face stream, backed either by a file or by a vector // |
| 222 |
////////////////////////////////////////////////////////////////////////////// |
| 223 |
// [WARNING] These assume that the stream starts as write-only and after the reset method is invoked, the stream becomes read-only. |
| 224 |
|
| 225 |
template< unsigned int FaceDim , bool InCore , bool Parallel > |
| 226 |
struct OutputInputFaceStream |
| 227 |
: public OutputFaceStream< FaceDim > |
| 228 |
, public InputFaceStream< FaceDim > |
| 229 |
{ |
| 230 |
// The streams for communicating the information |
| 231 |
InputFaceStream < FaceDim > * inStream; |
| 232 |
OutputFaceStream< FaceDim > *outStream; |
| 233 |
|
| 234 |
void reset( void ){ inStream->reset(); } |
| 235 |
bool read( Face< FaceDim > &f ){ return inStream->read( f); } |
| 236 |
bool read( unsigned int t , Face< FaceDim > &f ){ return inStream->read(t,f); } |
| 237 |
size_t write( const Face< FaceDim > &f ){ return outStream->write( f); } |
| 238 |
size_t write( unsigned int t , const Face< FaceDim > &f ){ return outStream->write(t,f); } |
| 239 |
size_t size( void ) const { return outStream->size(); } |
| 240 |
|
| 241 |
OutputInputFaceStream( void ) |
| 242 |
{ |
| 243 |
size_t sz = ThreadPool::NumThreads(); |
| 244 |
|
| 245 |
_backingVectors.resize( sz , nullptr ); |
| 246 |
|
| 247 |
_backingFiles.resize( sz , nullptr ); |
| 248 |
|
| 249 |
_inStreams.resize( sz , nullptr ); |
| 250 |
_outStreams.resize( sz , nullptr ); |
| 251 |
|
| 252 |
if constexpr( InCore ) |
| 253 |
{ |
| 254 |
if constexpr( Parallel ) |
| 255 |
{ |
| 256 |
for( unsigned int i=0 ; i<sz ; i++ ) |
| 257 |
{ |
| 258 |
_backingVectors[i] = new std::vector< Face< FaceDim > >(); |
| 259 |
_inStreams[i] = new VectorBackedInputDataStream< Face< FaceDim > >( *_backingVectors[i] ); |
| 260 |
_outStreams[i] = new VectorBackedOutputDataStream< Face< FaceDim > >( *_backingVectors[i] ); |
| 261 |
} |
| 262 |
inStream = new MultiInputDataStream< Face< FaceDim > >( _inStreams ); |
| 263 |
outStream = new MultiOutputDataStream< Face< FaceDim > >( _outStreams ); |
| 264 |
} |
| 265 |
else |
| 266 |
{ |
| 267 |
_backingVector = new std::vector< Face< FaceDim > >(); |
| 268 |
inStream = new VectorBackedInputDataStream< Face< FaceDim > >( *_backingVector ); |
| 269 |
outStream = new VectorBackedOutputDataStream< Face< FaceDim > >( *_backingVector ); |
| 270 |
} |
| 271 |
} |
| 272 |
else |
| 273 |
{ |
| 274 |
if constexpr( Parallel ) |
| 275 |
{ |
| 276 |
for( unsigned int i=0 ; i<sz ; i++ ) |
| 277 |
{ |
| 278 |
_backingFiles[i] = new FileBackedReadWriteStream::FileDescription( NULL ); |
| 279 |
_inStreams[i] = new FileBackedInputDataStream< Face< FaceDim > >( _backingFiles[i]->fp ); |
| 280 |
_outStreams[i] = new FileBackedOutputDataStream< Face< FaceDim > >( _backingFiles[i]->fp ); |
| 281 |
} |
| 282 |
inStream = new MultiInputDataStream< Face< FaceDim > >( _inStreams ); |
| 283 |
outStream = new MultiOutputDataStream< Face< FaceDim > >( _outStreams ); |
| 284 |
} |
| 285 |
else |
| 286 |
{ |
| 287 |
_backingFile = new FileBackedReadWriteStream::FileDescription( NULL ); |
| 288 |
inStream = new FileBackedInputDataStream< Face< FaceDim > >( _backingFile->fp ); |
| 289 |
outStream = new FileBackedOutputDataStream< Face< FaceDim > >( _backingFile->fp ); |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
~OutputInputFaceStream( void ) |
| 295 |
{ |
| 296 |
size_t sz = ThreadPool::NumThreads(); |
| 297 |
|
| 298 |
delete _backingVector; |
| 299 |
delete _backingFile; |
| 300 |
|
| 301 |
for( unsigned int i=0 ; i<sz ; i++ ) |
| 302 |
{ |
| 303 |
delete _backingVectors[i]; |
| 304 |
delete _backingFiles[i]; |
| 305 |
delete _inStreams[i]; |
| 306 |
delete _outStreams[i]; |
| 307 |
} |
| 308 |
|
| 309 |
delete inStream; |
| 310 |
delete outStream; |
| 311 |
} |
| 312 |
protected: |
| 313 |
std::vector< Face< FaceDim > > *_backingVector = nullptr; |
| 314 |
FileBackedReadWriteStream::FileDescription *_backingFile = nullptr; |
| 315 |
std::vector< std::vector< Face< FaceDim > > * > _backingVectors; |
| 316 |
std::vector< FileBackedReadWriteStream::FileDescription * > _backingFiles; |
| 317 |
std::vector< InputDataStream< Face< FaceDim > > * > _inStreams; |
| 318 |
std::vector< OutputDataStream< Face< FaceDim > > * > _outStreams; |
| 319 |
}; |
| 320 |
|
| 321 |
|
| 322 |
template< typename Real , unsigned int Dim , typename Factory , bool InCore , bool Parallel , typename ... Data > |
| 323 |
struct OutputInputFactoryTypeStream |
| 324 |
: public OutputDataStream< Position< Real , Dim > , Gradient< Real , Dim > , Weight< Real > , Data ... > |
| 325 |
, public InputDataStream< typename Factory::VertexType > |
| 326 |
{ |
| 327 |
using Vertex = typename Factory::VertexType; |
| 328 |
|
| 329 |
// The streams for communicating the information |
| 330 |
using OutputStreamType = OutputDataStream< Vertex >; |
| 331 |
using InputStreamType = InputDataStream< Vertex >; |
| 332 |
OutputStreamType *outStream; |
| 333 |
InputStreamType * inStream; |
| 334 |
|
| 335 |
void reset( void ){ inStream->reset(); } |
| 336 |
size_t write( const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > &w , const Data& ... d ) |
| 337 |
{ |
| 338 |
Vertex v = _converter( p , g , w , d... ); |
| 339 |
return outStream->write( v ); |
| 340 |
} |
| 341 |
size_t write( unsigned int thread , const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > &w , const Data& ... d ) |
| 342 |
{ |
| 343 |
Vertex v = _converter( p , g , w , d... ); |
| 344 |
return outStream->write( thread , v ); |
| 345 |
} |
| 346 |
bool read( Vertex &v ){ return inStream->read( v ); } |
| 347 |
bool read( unsigned int thread , Vertex &v ){ return inStream->read( thread , v ); } |
| 348 |
|
| 349 |
size_t size( void ) const { return outStream->size(); } |
| 350 |
|
| 351 |
OutputInputFactoryTypeStream( Factory &factory , std::function< Vertex ( const Position< Real , Dim > & , const Gradient< Real , Dim > & , const Weight< Real > & , const Data & ... ) > converter ) |
| 352 |
: _converter( converter ) |
| 353 |
{ |
| 354 |
size_t sz = ThreadPool::NumThreads(); |
| 355 |
|
| 356 |
_backingVectors.resize( sz , nullptr ); |
| 357 |
|
| 358 |
_backingFiles.resize( sz , nullptr ); |
| 359 |
|
| 360 |
_inStreams.resize( sz , nullptr ); |
| 361 |
_outStreams.resize( sz , nullptr ); |
| 362 |
|
| 363 |
if constexpr( Parallel ) |
| 364 |
{ |
| 365 |
for( unsigned int i=0 ; i<sz ; i++ ) |
| 366 |
{ |
| 367 |
if constexpr( InCore ) |
| 368 |
{ |
| 369 |
_backingVectors[i] = new std::vector< std::pair< size_t , Vertex > >(); |
| 370 |
_outStreams[i] = new VectorBackedOutputIndexedDataStream< Vertex >( *_backingVectors[i] ); |
| 371 |
_inStreams[i] = new VectorBackedInputIndexedDataStream< Vertex >( *_backingVectors[i] ); |
| 372 |
} |
| 373 |
else |
| 374 |
{ |
| 375 |
_backingFiles[i] = new FileBackedReadWriteStream::FileDescription( NULL ); |
| 376 |
_outStreams[i] = new FileBackedOutputIndexedFactoryTypeStream< Factory >( _backingFiles[i]->fp , factory ); |
| 377 |
_inStreams[i] = new FileBackedInputIndexedFactoryTypeStream< Factory >( _backingFiles[i]->fp , factory ); |
| 378 |
} |
| 379 |
} |
| 380 |
outStream = new DeInterleavedMultiOutputIndexedDataStream< Vertex >( _outStreams ); |
| 381 |
inStream = new InterleavedMultiInputIndexedDataStream< Vertex >( _inStreams ); |
| 382 |
} |
| 383 |
else |
| 384 |
{ |
| 385 |
if constexpr( InCore ) |
| 386 |
{ |
| 387 |
_backingVector = new std::vector< Vertex >(); |
| 388 |
outStream = new VectorBackedOutputDataStream< Vertex >( *_backingVector ); |
| 389 |
inStream = new VectorBackedInputDataStream< Vertex >( *_backingVector ); |
| 390 |
} |
| 391 |
else |
| 392 |
{ |
| 393 |
_backingFile = new FileBackedReadWriteStream::FileDescription( NULL ); |
| 394 |
outStream = new FileBackedOutputFactoryTypeStream< Factory >( _backingFile->fp , factory ); |
| 395 |
inStream = new FileBackedInputFactoryTypeStream< Factory >( _backingFile->fp , factory ); |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
~OutputInputFactoryTypeStream( void ) |
| 401 |
{ |
| 402 |
size_t sz = ThreadPool::NumThreads(); |
| 403 |
|
| 404 |
delete _backingVector; |
| 405 |
delete _backingFile; |
| 406 |
|
| 407 |
for( unsigned int i=0 ; i<sz ; i++ ) |
| 408 |
{ |
| 409 |
delete _backingVectors[i]; |
| 410 |
delete _backingFiles[i]; |
| 411 |
delete _inStreams[i]; |
| 412 |
delete _outStreams[i]; |
| 413 |
} |
| 414 |
|
| 415 |
delete inStream; |
| 416 |
delete outStream; |
| 417 |
delete _inMultiStream; |
| 418 |
} |
| 419 |
protected: |
| 420 |
std::function< Vertex ( const Position< Real , Dim > & , const Gradient< Real , Dim > & , const Weight< Real > & , const Data & ... ) > _converter; |
| 421 |
std::vector< Vertex > *_backingVector = nullptr; |
| 422 |
FileBackedReadWriteStream::FileDescription *_backingFile = nullptr; |
| 423 |
std::vector< std::vector< std::conditional_t< Parallel , std::pair< size_t , Vertex > , Vertex > > * >_backingVectors; |
| 424 |
std::vector< FileBackedReadWriteStream::FileDescription * > _backingFiles; |
| 425 |
std::vector< OutputIndexedDataStream< Vertex > * > _outStreams; |
| 426 |
std::vector< InputIndexedDataStream< Vertex > * > _inStreams; |
| 427 |
MultiInputIndexedDataStream< Vertex > *_inMultiStream = nullptr; |
| 428 |
}; |
| 429 |
|
| 430 |
template< typename Real , unsigned int Dim , bool HasGradients , bool HasDensity > |
| 431 |
struct OutputVertexInfo< Real , Dim , HasGradients , HasDensity > |
| 432 |
{ |
| 433 |
using Factory = |
| 434 |
typename std::conditional_t |
| 435 |
< |
| 436 |
HasGradients , |
| 437 |
typename std::conditional_t |
| 438 |
< |
| 439 |
HasDensity , |
| 440 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::NormalFactory< Real , Dim > , VertexFactory::ValueFactory< Real > > , |
| 441 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::NormalFactory< Real , Dim > > |
| 442 |
> , |
| 443 |
typename std::conditional_t |
| 444 |
< |
| 445 |
HasDensity , |
| 446 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::ValueFactory< Real > > , |
| 447 |
VertexFactory::PositionFactory< Real , Dim > |
| 448 |
> |
| 449 |
>; |
| 450 |
using Vertex = typename Factory::VertexType; |
| 451 |
|
| 452 |
static Factory GetFactory( void ){ return Factory(); } |
| 453 |
|
| 454 |
static Vertex Convert( const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > & w ) |
| 455 |
{ |
| 456 |
Vertex v; |
| 457 |
if constexpr( !HasGradients && !HasDensity ) v = p; |
| 458 |
else |
| 459 |
{ |
| 460 |
v.template get<0>() = p; |
| 461 |
if constexpr( HasGradients ) |
| 462 |
{ |
| 463 |
if constexpr( HasDensity ) v.template get<1>() = g , v.template get<2>() = w; |
| 464 |
else v.template get<1>() = g; |
| 465 |
} |
| 466 |
else |
| 467 |
{ |
| 468 |
if constexpr( HasDensity ) v.template get<1>() = w; |
| 469 |
} |
| 470 |
} |
| 471 |
return v; |
| 472 |
} |
| 473 |
}; |
| 474 |
|
| 475 |
template< typename Real , unsigned int Dim , bool HasGradients , bool HasDensity , typename AuxDataFactory > |
| 476 |
struct OutputVertexInfo< Real , Dim , HasGradients , HasDensity , AuxDataFactory > |
| 477 |
{ |
| 478 |
using Factory = |
| 479 |
typename std::conditional |
| 480 |
< |
| 481 |
HasGradients , |
| 482 |
typename std::conditional |
| 483 |
< |
| 484 |
HasDensity , |
| 485 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::NormalFactory< Real , Dim > , VertexFactory::ValueFactory< Real > , AuxDataFactory > , |
| 486 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::NormalFactory< Real , Dim > , AuxDataFactory > |
| 487 |
>::type , |
| 488 |
typename std::conditional |
| 489 |
< |
| 490 |
HasDensity , |
| 491 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , VertexFactory::ValueFactory< Real > , AuxDataFactory > , |
| 492 |
VertexFactory::Factory< Real , VertexFactory::PositionFactory< Real , Dim > , AuxDataFactory > |
| 493 |
>::type |
| 494 |
>::type; |
| 495 |
using AuxData = typename AuxDataFactory::VertexType; |
| 496 |
|
| 497 |
using _Vertex = DirectSum< Real , Point< Real , Dim > , Point< Real , Dim > , Real , typename AuxDataFactory::VertexType >; |
| 498 |
using Vertex = typename Factory::VertexType; |
| 499 |
|
| 500 |
static Factory GetFactory( AuxDataFactory auxDataFactory ) |
| 501 |
{ |
| 502 |
if constexpr( HasGradients ) |
| 503 |
{ |
| 504 |
if constexpr( HasDensity ) return Factory( VertexFactory::PositionFactory< Real , Dim >() , VertexFactory::NormalFactory< Real , Dim >() , VertexFactory::ValueFactory< Real >() , auxDataFactory ); |
| 505 |
else return Factory( VertexFactory::PositionFactory< Real , Dim >() , VertexFactory::NormalFactory< Real , Dim >() , auxDataFactory ); |
| 506 |
} |
| 507 |
else |
| 508 |
{ |
| 509 |
if constexpr( HasDensity ) return Factory( VertexFactory::PositionFactory< Real , Dim >() , VertexFactory::ValueFactory< Real >() , auxDataFactory ); |
| 510 |
else return Factory( VertexFactory::PositionFactory< Real , Dim >() , auxDataFactory ); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
static Vertex Convert( const Position< Real , Dim > &p , const Gradient< Real , Dim > &g , const Weight< Real > & w , const AuxData &data ) |
| 515 |
{ |
| 516 |
Vertex v; |
| 517 |
v.template get<0>() = p; |
| 518 |
if constexpr( HasGradients ) |
| 519 |
{ |
| 520 |
if constexpr( HasDensity ) v.template get<1>() = g , v.template get<2>() = w , v.template get<3>() = data; |
| 521 |
else v.template get<1>() = g , v.template get<2>() = data; |
| 522 |
} |
| 523 |
else |
| 524 |
{ |
| 525 |
if constexpr( HasDensity ) v.template get<1>() = w , v.template get<2>() = data; |
| 526 |
else v.template get<1>() = data; |
| 527 |
} |
| 528 |
return v; |
| 529 |
} |
| 530 |
}; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
#endif // RECONSTRUCTORS_STREAMS_INCLUDED |