7 int main(
int argc,
char *argv[])
11 const unsigned int VOXEL_COUNT=30;
12 v.
resize(VOXEL_COUNT,VOXEL_COUNT,VOXEL_COUNT);
14 const float VOX_SIZE=2;
16 Point3D(VOX_SIZE,VOX_SIZE,VOX_SIZE) );
21 const float SPHERE_RAD=1.0f;
22 const float SPHERE_RAD_SQR=SPHERE_RAD*SPHERE_RAD;
23 const Point3D pCentreA(-0.5f,-0.5f,-0.5f);
24 const Point3D pCentreB(0.5f,0.5f,0.5f);
27 cerr <<
"Creating synthetic voxel field...";
28 for(
auto ui=0;ui<VOXEL_COUNT;ui++)
30 for(
auto uj=0;uj<VOXEL_COUNT;uj++)
32 for(
auto uk=0;uk<VOXEL_COUNT;uk++)
37 if(p.
sqrDist(pCentreA) < SPHERE_RAD_SQR
38 || p.
sqrDist(pCentreB) < SPHERE_RAD_SQR)
46 cerr <<
"Done" << endl;
48 cerr <<
"Extracting isosurface (triangle soup)..." ;
49 vector<TriangleWithVertexNorm> surfTris;
51 cerr <<
"Done (" << surfTris.size() <<
" triangles)" << endl;
56 cerr <<
"Constructing mesh (deduplicating soup)...";
58 m.
nodes.resize(surfTris.size()*3);
61 for(
auto ui=0;ui<surfTris.size();ui++)
63 for(
auto uj=0;uj<3;uj++)
65 m.
nodes[3*ui+ uj]=surfTris[ui].p[uj];
74 2.0f*sqrt(std::numeric_limits<float>::epsilon()));
75 cerr <<
"Done" << endl;
79 cerr <<
"Generating synthetic points...";
80 const unsigned int NUM_POINTS=1000;
81 vector<Point3D> randomPoints;
82 randomPoints.resize(NUM_POINTS);
86 for(
auto ui=0;ui<NUM_POINTS;ui++)
89 x=2.0*VOX_SIZE*gsl_rng_uniform(r) -VOX_SIZE;
90 y=2.0*VOX_SIZE*gsl_rng_uniform(r) -VOX_SIZE;
91 z=2.0*VOX_SIZE*gsl_rng_uniform(r) -VOX_SIZE;
92 randomPoints[ui]=
Point3D(x,y,z);
95 cerr <<
"Done" << endl;
97 cerr <<
"Running signed-distance computation...";
105 vector<float> distances;
106 distances.resize(randomPoints.size());
108 #pragma omp parallel for 109 for(
auto ui=0;ui<randomPoints.size();ui++)
115 distances[ui]=-fabs(distances[ui]);
118 const char *OUTPUT_FILE=
"proxigram.txt";
119 ofstream fOut(OUTPUT_FILE);
123 cerr <<
"failed to open output file" << endl;
128 const unsigned int NBINS=50;
130 dMin=*std::min_element(distances.begin(),distances.end());
131 dMax=*std::max_element(distances.begin(),distances.end());
132 float delta = (dMax-dMin)/NBINS;
135 for(
auto ui=0;ui<hist.size();ui++)
136 fOut << ui*delta+dMin <<
"\t" << hist[ui] << endl;
138 cerr <<
"Done. Output written to :" << OUTPUT_FILE << endl;
float sqrDist(const Point3D &pt) const
Returns the square of distance to another Point3D.
size_t resize(size_t newX, size_t newY, size_t newZ, const AtomProbe::Point3D &newMinBound=AtomProbe::Point3D(0.0f, 0.0f, 0.0f), const AtomProbe::Point3D &newMaxBound=AtomProbe::Point3D(1.0f, 1.0f, 1.0f))
Resize the data field.
void getBounds(AtomProbe::Point3D &pMin, AtomProbe::Point3D &pMax) const
Get the bounding size.
Template class that stores 3D voxel data.
Simple mesh class for storing and manipulating meshes consisting of 2 and 3D simplexes (triangles or ...
size_t getNearestTri(const Point3D &p, float &distance) const
Find the nearest triangle to a particular point.
void fill(const T &val)
Fill all voxels with a given value.
A 3D point data class storage.
AtomProbe::Point3D getPoint(size_t x, size_t y, size_t z) const
Get the position associated with an XYZ voxel.
std::vector< Point3D > nodes
Point storage for 3D Data (nodes/coords/vertices..)
void setBounds(const AtomProbe::Point3D &pMin, const AtomProbe::Point3D &pMax)
Set the bounding size.
void linearHistogram(const std::vector< T > &data, T start, T end, T step, std::vector< T > &histVals)
int main(int argc, char *argv[])
Helper class to define a bounding cube.
void setData(size_t x, size_t y, size_t z, const T &val)
Retrieve a reference to the data ata given position.
void mergeDuplicateVertices(float tolerance)
void pointsInside(const std::vector< Point3D > &p, std::vector< bool > &meshResults, unsigned int &prog) const
Find the points that lie inside a this mesh.
gsl_rng * getRng() const
Obtain a GSL random number generator.
std::vector< TRIANGLE > triangles
Storage for node connectivity in triangle form (take in groups of 3)
void marchingCubes(const Voxels< float > &v, float isoValue, std::vector< TriangleWithVertexNorm > &tVec)