PoissonReconstructionT.cc 4.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//=============================================================================
//
//  CLASS PoissonReconstructionT - IMPLEMENTATION
//
//=============================================================================

#define ACG_POISSONRECONSTRUCTIONT_C

//== INCLUDES =================================================================

#include "PoissonReconstructionT.hh"


//== NAMESPACES ===============================================================

namespace ACG {

//== IMPLEMENTATION ==========================================================

void DumpOutput( const char* format , ... )
{
22 23 24 25
  va_list args;
  va_start( args , format );
  vprintf( format , args );
  va_end( args );
26 27 28 29 30 31 32 33 34 35 36 37 38
}

template <class MeshT>
bool
PoissonReconstructionT<MeshT>::
run( std::vector< Real >& _pt_data, MeshT& _mesh, const Parameter& _parameter )
{

    m_parameter = _parameter;

    Real isoValue = 0;

    Octree<2> tree;
Jan Möbius's avatar
Jan Möbius committed
39
#ifdef USE_OMP
40
    tree.threads = omp_get_num_procs();
Jan Möbius's avatar
Jan Möbius committed
41 42 43
#else
    tree.threads = 1;
#endif
44 45
    TreeOctNode::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE );

46
    std::cerr << "Tree construction with depth " << m_parameter.Depth << std::endl;
47 48
    tree.setBSplineData( m_parameter.Depth );
    double maxMemoryUsage;
49
    tree.maxMemoryUsage=0;
50 51 52
    XForm4x4< Real > xForm = XForm4x4< Real >::Identity();
    int pointCount = tree.setTreeMemory( _pt_data ,  m_parameter.Depth ,  m_parameter.MinDepth , m_parameter.Depth , Real(m_parameter.SamplesPerNode),
                                         m_parameter.Scale , m_parameter.Confidence , m_parameter.PointWeight , m_parameter.AdaptiveExponent , xForm );
53

54 55 56 57 58 59
    if (pointCount <= 0)
    {
      std::cerr << "Invalid Input Points" << std::endl;
      return false;
    }

60 61
    std::cerr << "Tree Clipping" << std::endl;

62
    tree.ClipTree();
63 64

    std::cerr << "Tree Finalize" << std::endl;
65 66 67 68 69 70 71
    tree.finalize( m_parameter.IsoDivide );

    DumpOutput( "Input Points: %d\n" , pointCount );
    DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() );
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );

    maxMemoryUsage = tree.maxMemoryUsage;
72
    tree.maxMemoryUsage=0;
73 74 75 76
    tree.SetLaplacianConstraints();
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );
    maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

77
    tree.maxMemoryUsage=0;
78 79 80 81 82 83
    tree.LaplacianMatrixIteration( m_parameter.SolverDivide, m_parameter.ShowResidual, m_parameter.MinIters, m_parameter.SolverAccuracy, m_parameter.Depth, m_parameter.FixedIters );
    DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
    maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

    CoredFileMeshData mesh;
    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 88
    DumpOutput( "Iso-Value: %e\n" , isoValue );

89
    tree.maxMemoryUsage = 0;
90 91 92 93 94
    tree.GetMCIsoTriangles( isoValue , m_parameter.IsoDivide , &mesh );

    _mesh.clear();
    mesh.resetIterator();

95
    DumpOutput( "Time for Iso: %f\n" , Time()-time );
96 97 98 99 100 101 102 103 104 105 106











Jan Möbius's avatar
Jan Möbius committed
107
//    int nr_vertices=int(mesh.outOfCorePointCount()+mesh.inCorePoints.size());
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    int nr_faces=mesh.polygonCount();

    mesh.resetIterator();

    //
    // describe vertex and face properties
    //

    // write vertices
    Point3D< float > p;
    for( int i=0 ; i < int( mesh.inCorePoints.size() ) ; i++ )
    {
        p = mesh.inCorePoints[i];
        _mesh.add_vertex( typename MeshT::Point(p[0],p[1],p[2]) );
    }
    for( int i=0; i<mesh.outOfCorePointCount() ; i++ )
    {
        mesh.nextOutOfCorePoint(p);
        _mesh.add_vertex( typename MeshT::Point(p[0],p[1],p[2]) );

    }  // for, write vertices

    // write faces
    std::vector< CoredVertexIndex > polygon;
    for( int i=0 ; i<nr_faces ; i++ )
    {
        //
        // create and fill a struct that the ply code can handle
        //
        mesh.nextPolygon( polygon );
        std::vector< typename MeshT::VertexHandle > face;
        for( int i=0 ; i<int( polygon.size() ) ; i++ )
            if( polygon[i].inCore ) face.push_back( _mesh.vertex_handle( polygon[i].idx ) );
            else                    face.push_back( _mesh.vertex_handle( polygon[i].idx + int( mesh.inCorePoints.size() ) ) );

        _mesh.add_face( face );

    }  // for, write faces

    _mesh.update_normals();

    return true;
}

//-----------------------------------------------------------------------------



//=============================================================================
} // namespace ACG
//=============================================================================