Skip to content

Commit

Permalink
Merge pull request #252 from mleotta/dev/volume-improvements
Browse files Browse the repository at this point in the history
Volume improvements
  • Loading branch information
mleotta authored Jul 17, 2017
2 parents c462ab6 + faa85dd commit 0dfed48
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 97 deletions.
4 changes: 2 additions & 2 deletions doc/manuals/telesculptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Tool Bar
Toggles visibility of the depth map (if avaialble) rendered as a 3D point
cloud or mesh; see `3D Depth Map Options`_.

:icon:`blank` Surface from Volume
:icon:`volume` Surface from Volume
Toggles the visibility of the surface mesh extracted from volumetric data.
This option is disabled if no volume data is loaded; see
`Volume Surface Options`_.
Expand Down Expand Up @@ -167,7 +167,7 @@ view as well. See `Depth Map View`_.
Volume Surface Options
----------------------

The :action:`- Volume from Surface` pop-up provides additional controls on the
The :action:`volume Volume from Surface` pop-up provides additional controls on the
extraction and coloring of a surface from volumetric data. The "Surface
threshold" parameter controls the value of the iso-surface at which the surface
is extracted from the volume. The "Colorize surface" option, if checked,
Expand Down
2 changes: 0 additions & 2 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ set(gui_moc_headers
tools/BundleAdjustTool.h
tools/CanonicalTransformTool.h
tools/InitCamerasLandmarksTool.h
tools/MeshColoration.h
tools/NeckerReversalTool.h
tools/ReconstructionData.h
tools/TrackFilterTool.h
tools/TrackFeaturesTool.h
)
Expand Down
4 changes: 4 additions & 0 deletions gui/Project.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ bool Project::read(QString const& path)
{
this->volumePath = getPath(config, base, "volume_file");
this->imageListPath = getPath(config, base, "image_list_file");
if (this->imageListPath.isEmpty())
{
this->imageListPath = getPath(config, base, "video_source");
}
}

return true;
Expand Down
4 changes: 4 additions & 0 deletions gui/WorldView.ui
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/22x22/volume</normaloff>:/icons/22x22/volume</iconset>
</property>
<property name="enabled">
<bool>false</bool>
</property>
Expand Down
Binary file added gui/icons/16x16/volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/22x22/volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions gui/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<file alias="residual">16x16/residual.png</file>
<file alias="save">16x16/save.png</file>
<file alias="view-reset">16x16/view-reset.png</file>
<file alias="volume">16x16/volume.png</file>
</qresource>
<qresource prefix="icons/22x22">
<file alias="camera">22x22/camera.png</file>
Expand All @@ -37,6 +38,7 @@
<file alias="residual">22x22/residual.png</file>
<file alias="save">22x22/save.png</file>
<file alias="view-reset">22x22/view-reset.png</file>
<file alias="volume">22x22/volume.png</file>
</qresource>
<qresource prefix="icons/32x32">
<file alias="telesculptor">32x32/telesculptor.png</file>
Expand Down
270 changes: 208 additions & 62 deletions gui/icons/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 22 additions & 15 deletions gui/tools/MeshColoration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ static std::vector<std::string> ExtractAllKRTDFilePath(const char* globalPath, c


//----------------------------------------------------------------------------
// Description
// Compute median of a vector
/// Compute median of a vector
template <typename T>
static void ComputeMedian(std::vector<T> vector, double& median)
{
Expand Down Expand Up @@ -178,35 +177,41 @@ MeshColoration::MeshColoration(vtkPolyData* mesh, std::string frameList, std::st
this->frameList = ExtractAllFilePath(frameList.c_str());
this->krtdFolder = ExtractAllKRTDFilePath(krtdFolder.c_str(), frameList.c_str());
if (this->krtdFolder.size() < frameList.size())
{
{
std::cerr << "Error, not enough krtd file for each vti file" << std::endl;
return;
}
}

}

MeshColoration::~MeshColoration()
{
if (this->OutputMesh != 0)
{
this->OutputMesh->Delete();
for (int i = 0; i < this->DataList.size(); i++)
{
}
for (size_t i = 0; i < this->DataList.size(); i++)
{
delete this->DataList[i];
}
}
this->DataList.clear();
}

void MeshColoration::SetInput(vtkPolyData* mesh)
{
if (this->OutputMesh != 0)
{
this->OutputMesh->Delete();
}
this->OutputMesh = mesh;
}

void MeshColoration::SetFrameSampling(int sample)
{
if (sample < 1)
{
return;
}
this->Sampling = sample;
}

Expand All @@ -222,10 +227,10 @@ bool MeshColoration::ProcessColoration(std::string currentVtiPath)
int nbDepthMap = (int)this->DataList.size();

if (this->OutputMesh == 0 || nbDepthMap == 0 /*|| this->Sampling >= nbDepthMap*/)
{
{
std::cerr << "Error when input has been set or during reading vti/krtd file path" << std::endl;
return false;
}
}

vtkPoints* meshPointList = this->OutputMesh->GetPoints();
if (meshPointList == 0)
Expand Down Expand Up @@ -280,24 +285,26 @@ bool MeshColoration::ProcessColoration(std::string currentVtiPath)


for (int idData = 0; idData < nbDepthMap; idData++)
{
{
ReconstructionData* data = this->DataList[idData];
vtkVector3d cameraCenter = data->GetCameraCenter();
// Check if the 3D point is in front of the camera
vtkVector3d cameraPointVec = vtkVector3d( position[0] - cameraCenter(0),
position[1] - cameraCenter(1),
position[2] - cameraCenter(2) );
if (cameraPointVec.Dot(pointNormal)>0.0)
{
continue;
}
// project 3D point to pixel coordinates
int pixelPosition[2];
data->TransformWorldToDepthMapPosition(position, pixelPosition);
// Test if pixel is inside depth map
if (pixelPosition[0] < 0 || pixelPosition[0] >= depthMapDimensions[0] ||
pixelPosition[1] < 0 || pixelPosition[1] >= depthMapDimensions[1])
{
{
continue;
}
}

double color[3];
data->GetColorValue(pixelPosition, color);
Expand All @@ -309,7 +316,7 @@ bool MeshColoration::ProcessColoration(std::string currentVtiPath)

// If we get elements
if (list0.size() != 0)
{
{
double sum0 = std::accumulate(list0.begin(), list0.end(), 0);
double sum1 = std::accumulate(list1.begin(), list1.end(), 0);
double sum2 = std::accumulate(list2.begin(), list2.end(), 0);
Expand All @@ -321,7 +328,7 @@ bool MeshColoration::ProcessColoration(std::string currentVtiPath)
ComputeMedian<double>(list2, median2);
medianValues->SetTuple3(id, median0, median1, median2);
projectedDMValue->SetTuple1(id, list0.size());
}
}

list0.clear();
list1.clear();
Expand All @@ -337,7 +344,7 @@ bool MeshColoration::ProcessColoration(std::string currentVtiPath)

void MeshColoration::initializeDataList(std::string currentVtiPath)
{
int nbDepthMap = (int)frameList.size();
int nbDepthMap = (int)frameList.size();

//Take a subset of depthmap
if (currentVtiPath == "")
Expand Down
51 changes: 35 additions & 16 deletions gui/tools/ReconstructionData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
// VTK includes
#include "vtkDoubleArray.h"
#include "vtkImageData.h"
#include "vtkImageReader2Factory.h"
#include "vtkImageReader2.h"
#include "vtkVector.h"
#include "vtkMatrix3x3.h"
#include "vtkMatrix4x4.h"
Expand All @@ -44,7 +46,6 @@
#include "vtkSmartPointer.h"
#include "vtkTransform.h"
#include "vtkUnsignedCharArray.h"
#include "vtkPNGReader.h"


namespace
Expand Down Expand Up @@ -161,25 +162,33 @@ ReconstructionData::ReconstructionData(std::string depthPath,
ReconstructionData::~ReconstructionData()
{
if (this->DepthMap)
{
this->DepthMap->Delete();
}
if (this->MatrixK)
{
this->MatrixK->Delete();
}
if (this->MatrixRT)
{
this->MatrixRT->Delete();
}
if (this->Matrix4K)
{
this->Matrix4K->Delete();
}
}

void ReconstructionData::GetColorValue(int* pixelPosition, double rgb[3])
{
vtkUnsignedCharArray* color =
vtkUnsignedCharArray::SafeDownCast(this->DepthMap->GetPointData()->GetArray("PNGImage"));
vtkUnsignedCharArray::SafeDownCast(this->DepthMap->GetPointData()->GetArray(0));

if (color == 0)
{
{
std::cerr << "Error, no 'Color' array exists" << std::endl;
return;
}
}

int* depthDims = this->DepthMap->GetDimensions();

Expand Down Expand Up @@ -241,24 +250,24 @@ void ReconstructionData::ApplyDepthThresholdFilter(double thresholdBestCost)
vtkDoubleArray::SafeDownCast(this->DepthMap->GetPointData()->GetArray("Best Cost Values"));

if (depths == 0)
{
{
std::cerr << "Error during threshold, depths is empty" << std::endl;
return;
}
}

int nbTuples = depths->GetNumberOfTuples();

if (bestCost->GetNumberOfTuples() != nbTuples)
return;

for (int i = 0; i < nbTuples; i++)
{
{
double v_bestCost = bestCost->GetTuple1(i);
if (v_bestCost > thresholdBestCost)
{
{
depths->SetTuple1(i, -1);
}
}
}
}

void ReconstructionData::TransformWorldToDepthMapPosition(const double* worldCoordinate,
Expand All @@ -279,46 +288,56 @@ void ReconstructionData::TransformWorldToDepthMapPosition(const double* worldCoo
void ReconstructionData::SetDepthMap(vtkImageData* data)
{
if (this->DepthMap != 0)
{
this->DepthMap->Delete();
}
this->DepthMap = data;
this->DepthMap->Register(0);
}

void ReconstructionData::SetMatrixK(vtkMatrix3x3* matrix)
{
if (this->MatrixK != 0)
{
this->MatrixK->Delete();
}
this->MatrixK = matrix;
this->MatrixK->Register(0);

if (this->Matrix4K != 0)
{
this->Matrix4K->Delete();
}
this->Matrix4K = vtkMatrix4x4::New();
this->Matrix4K->Identity();
for (int i = 0; i < 3; i++)
{
{
for (int j = 0; j < 3; j++)
{
{
this->Matrix4K->SetElement(i, j, this->MatrixK->GetElement(i, j));
}
}
}

this->TransformCameraToDepthMap->SetMatrix(this->Matrix4K);
}

void ReconstructionData::SetMatrixRT(vtkMatrix4x4* matrix)
{
if (this->MatrixRT != 0)
{
this->MatrixRT->Delete();
}
this->MatrixRT = matrix;
this->MatrixRT->Register(0);
this->TransformWorldToCamera->SetMatrix(this->MatrixRT);
}

void ReconstructionData::ReadDepthMap(std::string path, vtkImageData* out)
{
vtkSmartPointer<vtkPNGReader> depthMapReader = vtkSmartPointer<vtkPNGReader>::New();
depthMapReader->SetFileName(path.c_str());
depthMapReader->Update();
out->ShallowCopy(depthMapReader->GetOutput());
vtkSmartPointer<vtkImageReader2Factory> readerFactory =
vtkSmartPointer<vtkImageReader2Factory>::New();
vtkSmartPointer<vtkImageReader2> imageReader = readerFactory->CreateImageReader2(path.c_str());
imageReader->SetFileName(path.c_str());
imageReader->Update();
out->ShallowCopy(imageReader->GetOutput());
}

0 comments on commit 0dfed48

Please sign in to comment.