| 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 |
#ifndef POINT_PARTITION_INCLUDED |
| 30 |
#define POINT_PARTITION_INCLUDED |
| 31 |
|
| 32 |
#include <string> |
| 33 |
#include <sstream> |
| 34 |
#include <filesystem> |
| 35 |
#include "Streams.h" |
| 36 |
#include "MyMiscellany.h" |
| 37 |
#include "Ply.h" |
| 38 |
#include "DataStream.h" |
| 39 |
#include "PointExtent.h" |
| 40 |
|
| 41 |
namespace PoissonRecon |
| 42 |
{ |
| 43 |
static const unsigned int BUFFER_IO = 1<<14; // Buffer the points before reading/writing |
| 44 |
|
| 45 |
|
| 46 |
namespace PointPartition |
| 47 |
{ |
| 48 |
template< typename Real , unsigned int Dim > |
| 49 |
struct PointSetInfo |
| 50 |
{ |
| 51 |
std::string header; |
| 52 |
unsigned filesPerDir; |
| 53 |
XForm< Real , Dim+1 > modelToUnitCube; |
| 54 |
std::vector< size_t > pointsPerSlab; |
| 55 |
std::vector< PlyProperty > auxiliaryProperties; |
| 56 |
|
| 57 |
PointSetInfo( void ); |
| 58 |
PointSetInfo( unsigned int slabs ); |
| 59 |
PointSetInfo( BinaryStream &stream ); |
| 60 |
|
| 61 |
void write( BinaryStream &stream ) const; |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
struct Partition |
| 66 |
{ |
| 67 |
Partition( void ); |
| 68 |
Partition( unsigned int dCount , const std::vector< size_t > &slabSizes ); |
| 69 |
|
| 70 |
#ifdef ADAPTIVE_PADDING |
| 71 |
void optimize( bool useMax ); |
| 72 |
std::pair< unsigned int , unsigned int > range( unsigned int i ) const; |
| 73 |
size_t size( unsigned int i ) const; |
| 74 |
void printDistribution( void ) const; |
| 75 |
double l2Energy( void ) const; |
| 76 |
double maxEnergy( void ) const; |
| 77 |
#else // !ADAPTIVE_PADDING |
| 78 |
void optimize( bool useMax , unsigned int padSize ); |
| 79 |
std::pair< unsigned int , unsigned int > range( unsigned int i , unsigned int padSize ) const; |
| 80 |
size_t size( unsigned int i , unsigned int padSize ) const; |
| 81 |
void printDistribution( unsigned int padSize ) const; |
| 82 |
double l2Energy( unsigned int padSize ) const; |
| 83 |
double maxEnergy( unsigned int padSize ) const; |
| 84 |
#endif // ADAPTIVE_PADDING |
| 85 |
size_t size( void ) const; |
| 86 |
unsigned int partitions( void ) const; |
| 87 |
unsigned int slabs( void ) const; |
| 88 |
|
| 89 |
protected: |
| 90 |
std::vector< unsigned int > _starts; |
| 91 |
std::vector< size_t > _slabSizes; |
| 92 |
}; |
| 93 |
|
| 94 |
long ReadPLYProperties( FILE *fp , std::vector< PlyProperty > &properties ); |
| 95 |
long ReadPLYProperties( const char *fileName , std::vector< PlyProperty > &properties ); |
| 96 |
long WritePLYProperties( FILE *fp , const std::vector< PlyProperty > &properties ); |
| 97 |
long WritePLYProperties( const char *fileName , const std::vector< PlyProperty > &properties ); |
| 98 |
|
| 99 |
template< typename InputFactory > |
| 100 |
struct BufferedBinaryInputDataStream : public InputDataStream< typename InputFactory::VertexType > |
| 101 |
{ |
| 102 |
|
| 103 |
typedef typename InputFactory::VertexType Data; |
| 104 |
BufferedBinaryInputDataStream( const char *fileName , const InputFactory &factory , size_t bufferSize ); |
| 105 |
~BufferedBinaryInputDataStream( void ); |
| 106 |
void reset( void ); |
| 107 |
bool read( Data &d ); |
| 108 |
protected: |
| 109 |
size_t _bufferSize , _current , _inBuffer , _elementSize; |
| 110 |
Pointer( char ) _buffer; |
| 111 |
FILE *_fp; |
| 112 |
const InputFactory &_factory; |
| 113 |
long _inset; |
| 114 |
}; |
| 115 |
|
| 116 |
template< typename OutputFactory > |
| 117 |
struct BufferedBinaryOutputDataStream : public OutputDataStream< typename OutputFactory::VertexType > |
| 118 |
{ |
| 119 |
typedef typename OutputFactory::VertexType Data; |
| 120 |
BufferedBinaryOutputDataStream( const char *fileName , const OutputFactory &factory , size_t bufferSize ); |
| 121 |
~BufferedBinaryOutputDataStream( void ); |
| 122 |
void reset( void ); |
| 123 |
size_t write( const Data &d ); |
| 124 |
size_t size( void ) const; |
| 125 |
protected: |
| 126 |
size_t _bufferSize , _current , _elementSize; |
| 127 |
Pointer( char ) _buffer; |
| 128 |
FILE *_fp; |
| 129 |
const OutputFactory &_factory; |
| 130 |
long _inset; |
| 131 |
}; |
| 132 |
|
| 133 |
void RemovePointSlabDirs( std::string dir ); |
| 134 |
static void CreatePointSlabDirs( std::string dir , unsigned int count , unsigned int filesPerDir ); |
| 135 |
|
| 136 |
std::string FileDir( std::string dir , std::string header ); |
| 137 |
std::string FileDir( std::string dir , std::string header , unsigned int clientIndex ); |
| 138 |
|
| 139 |
std::string FileName( std::string dir , unsigned int slab , unsigned int slabs , unsigned int filesPerDir ); |
| 140 |
std::string FileName( std::string dir , std::string header , unsigned int slab , unsigned int slabs , unsigned int filesPerDir ); |
| 141 |
std::string FileName( std::string dir , std::string header , unsigned int clientIndex , unsigned int slab , unsigned int slabs , unsigned int filesPerDir ); |
| 142 |
|
| 143 |
std::string PointSetInfoName( std::string dir , std::string header ); |
| 144 |
|
| 145 |
#include "PointPartition.inl" |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
#endif // POINT_PARTITION_INCLUDED |