Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rough attempt at dynamic clipping planes for point clouds #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static bool plyHasMesh(QString fileName)

//------------------------------------------------------------------------------
Geometry::Geometry()
: m_fileName(),
: m_spatialResolution(1.0),
m_fileName(),
m_offset(0,0,0),
m_centroid(0,0,0),
m_bbox()
Expand Down
6 changes: 6 additions & 0 deletions src/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Geometry : public QObject
double* distance = 0,
std::string* info = 0) const = 0;


//--------------------------------------------------
/// Get file name describing the source of the geometry
const QString& fileName() const { return m_fileName; }
Expand All @@ -143,6 +144,9 @@ class Geometry : public QObject
/// Get axis aligned bounding box containing the geometry
const Imath::Box3d& boundingBox() const { return m_bbox; }

/// Get esimate for the smallest spatial scale of interest
float spatialResolution() const { return m_spatialResolution; }

signals:
/// Emitted at the start of a point loading step
void loadStepStarted(QString stepDescription);
Expand All @@ -155,6 +159,8 @@ class Geometry : public QObject
void setCentroid(const V3d& centroid) { m_centroid = centroid; }
void setBoundingBox(const Imath::Box3d& bbox) { m_bbox = bbox; }

float m_spatialResolution;

private:
QString m_fileName;
V3d m_offset;
Expand Down
32 changes: 32 additions & 0 deletions src/pointarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ struct OctreeNode
longitudinalScale, &thisRClosest);
}

void spatialResolution(const V3f *const p, float& sumRMin, size_t& count) const
{
if(endIndex == beginIndex)
{
for (int i = 0; i < 8; ++i)
if(children[i])
children[i]->spatialResolution(p, sumRMin, count);
}
else
{
for(size_t i = beginIndex; i < endIndex - 1; i += 1000)
{
float rMin = FLT_MAX;
for(size_t j = i+1; j < endIndex; ++j)
{
const float r = (p[j] - p[i]).length2();
rMin = r < rMin ? r : rMin;
}
sumRMin += sqrtf(rMin);
count++;
}
}
}


size_t size() const { return endIndex - beginIndex; }

bool isLeaf() const { return beginIndex != endIndex; }
Expand Down Expand Up @@ -406,6 +431,13 @@ bool PointArray::loadFile(QString fileName, size_t maxPointCount)
}
m_P = (V3f*)m_fields[m_positionFieldIdx].as<float>();

float rMin = 0;
size_t count = 0;
m_rootNode.get()->spatialResolution(m_P, rMin, count);

m_spatialResolution = rMin/count;
printf("m_spatialResolution = %f\n", m_spatialResolution);

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/view3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ void View3D::geometryInserted(const QModelIndex& /*unused*/, int firstRow, int l
const GeometryCollection::GeometryVec& geoms = m_geometries->get();
for (int i = firstRow; i <= lastRow; ++i)
geoms[i]->initializeGL();

float minSpatialResolution = geoms[0]->spatialResolution();
Imath::Box3d bbox = geoms[0]->boundingBox();
for(size_t i = 1; i < geoms.size(); ++i)
{
minSpatialResolution = std::min(minSpatialResolution, geoms[i]->spatialResolution());
bbox.extendBy(geoms[i]->boundingBox());
}
m_camera.setClipNear(minSpatialResolution);
m_camera.setClipFar(2*(bbox.max - bbox.min).length());
geometryChanged();
}

Expand Down