Removed macros.h and pimpl

This commit is contained in:
Paolo Andreetto
2019-05-10 13:22:00 +00:00
parent c00e4a6382
commit d02a095028
16 changed files with 363 additions and 490 deletions

View File

@@ -29,25 +29,6 @@
#include "config.h"
#endif
#include <vtkLine.h>
#include <vtkCellArray.h>
#include <vtkLineSource.h>
#include <vtkSphereSource.h>
#include <vtkBoundingBox.h>
#include <vtkCubeSource.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkAppendPolyData.h>
#include <vtkActor.h>
#include <vtkAssembly.h>
#include <vtkProp3DCollection.h>
#include <vtkProperty.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include "vtkVoxRaytracerRepresentation.h"
@@ -60,59 +41,6 @@
namespace uLib {
namespace Vtk {
///// PIMPL ////////////////////////////////////////////////////////////////////
class vtkVoxRaytracerRepresentationPimpl {
public:
vtkVoxRaytracerRepresentationPimpl(VoxRaytracer &content) :
m_Content(&content),
m_Assembly(vtkAssembly::New()),
m_Sphere1(vtkSphereSource::New()),
m_Sphere2(vtkSphereSource::New()),
m_Line1(vtkLineSource::New()),
m_Line2(vtkLineSource::New()),
m_Line3(vtkLineSource::New()),
m_RayLine(vtkAppendPolyData::New()),
m_RayLineActor(vtkActor::New()),
m_RayRepresentation(vtkAppendPolyData::New()),
m_RayRepresentationActor(vtkActor::New()),
m_Transform(vtkTransform::New())
{
default_radius = content.GetImage()->GetSpacing()(0)/4;
m_Sphere1->SetRadius(default_radius);
m_Sphere2->SetRadius(default_radius);
m_SelectedElement = m_RayLine;
}
~vtkVoxRaytracerRepresentationPimpl()
{
m_Assembly->Delete();
m_RayLine->Delete();
m_RayLineActor->Delete();
m_RayRepresentationActor->Delete();
m_Transform->Delete();
}
// members //
VoxRaytracer *m_Content;
Scalarf default_radius;
vtkAssembly *m_Assembly;
vtkAppendPolyData *m_RayLine;
vtkActor *m_RayLineActor;
vtkActor *m_RayRepresentationActor;
vtkSmartPointer<vtkTransform> m_Transform;
VoxRaytracer::RayData m_Ray;
vtkSmartPointer<vtkSphereSource> m_Sphere1,m_Sphere2;
vtkSmartPointer<vtkLineSource> m_Line1, m_Line2, m_Line3;
vtkSmartPointer<vtkAppendPolyData> m_RayRepresentation;
vtkAppendPolyData *m_SelectedElement;
};
////////////////////////////////////////////////////////////////////////////////
////// VOX RAYTRACER REPRESENTATION ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -120,44 +48,64 @@ public:
vtkVoxRaytracerRepresentation::vtkVoxRaytracerRepresentation(Content &content) :
d(new vtkVoxRaytracerRepresentationPimpl(content))
m_Content(&content),
m_Assembly(vtkAssembly::New()),
m_Sphere1(vtkSphereSource::New()),
m_Sphere2(vtkSphereSource::New()),
m_Line1(vtkLineSource::New()),
m_Line2(vtkLineSource::New()),
m_Line3(vtkLineSource::New()),
m_RayLine(vtkAppendPolyData::New()),
m_RayLineActor(vtkActor::New()),
m_RayRepresentation(vtkAppendPolyData::New()),
m_RayRepresentationActor(vtkActor::New()),
m_Transform(vtkTransform::New())
{
default_radius = content.GetImage()->GetSpacing()(0)/4;
m_Sphere1->SetRadius(default_radius);
m_Sphere2->SetRadius(default_radius);
m_SelectedElement = m_RayLine;
InstallPipe();
}
vtkVoxRaytracerRepresentation::~vtkVoxRaytracerRepresentation()
{
delete d;
m_Assembly->Delete();
m_RayLine->Delete();
m_RayLineActor->Delete();
m_RayRepresentationActor->Delete();
m_Transform->Delete();
}
VoxRaytracer *vtkVoxRaytracerRepresentation::GetRaytracerAlgorithm()
{
return d->m_Content;
return m_Content;
}
vtkProp *vtkVoxRaytracerRepresentation::GetProp()
{
return d->m_Assembly;
return m_Assembly;
}
vtkPolyData *vtkVoxRaytracerRepresentation::GetPolyData() const
{
std::cout << "get Raytracer polydata\n";
d->m_SelectedElement->Update();
return d->m_SelectedElement->GetOutput();
m_SelectedElement->Update();
return m_SelectedElement->GetOutput();
}
void vtkVoxRaytracerRepresentation::SetRepresentationElements(vtkVoxRaytracerRepresentation::RepresentationElements el)
{
switch(el) {
case Vtk::vtkVoxRaytracerRepresentation::RayElements:
d->m_SelectedElement = d->m_RayLine;
m_SelectedElement = m_RayLine;
break;
case Vtk::vtkVoxRaytracerRepresentation::VoxelsElements:
d->m_SelectedElement = d->m_RayRepresentation;
m_SelectedElement = m_RayRepresentation;
break;
default:
d->m_SelectedElement = d->m_RayLine;
m_SelectedElement = m_RayLine;
break;
}
}
@@ -167,22 +115,22 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon)
{
HPoint3f pt1,pt2,src;
src = muon.LineIn().origin;
d->m_Content->GetEntryPoint(muon.LineIn(),pt1);
d->m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2));
d->m_Line1->SetPoint1(src(0),src(1),src(2));
d->m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2));
m_Content->GetEntryPoint(muon.LineIn(),pt1);
m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2));
m_Line1->SetPoint1(src(0),src(1),src(2));
m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2));
HLine3f line_out = muon.LineOut();
src = line_out.origin;
float *direction = line_out.direction.data();
for(int i=0;i<3;++i) direction[i] *= -1;
d->m_Content->GetEntryPoint(line_out,pt2);
d->m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2));
d->m_Line2->SetPoint1(src(0),src(1),src(2));
d->m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2));
m_Content->GetEntryPoint(line_out,pt2);
m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2));
m_Line2->SetPoint1(src(0),src(1),src(2));
m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2));
d->m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2));
d->m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2));
m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2));
m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2));
// Create a vtkPoints object and store the points in it
vtkSmartPointer<vtkPoints> points =
@@ -210,25 +158,22 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon)
// Add the lines to the dataset
linesPolyData->SetLines(lines);
d->m_RayLine->RemoveAllInputs();
m_RayLine->RemoveAllInputs();
# if VTK_MAJOR_VERSION <= 5
d->m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
# else
d->m_RayLine->AddInputData(linesPolyData);
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
# endif
d->m_RayLine->AddInputConnection(d->m_Line1->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Sphere1->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Line2->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Sphere2->GetOutputPort());
// d->m_RayLine->AddInputConnection(d->m_Line3->GetOutputPort());
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
m_RayLine->AddInputConnection(m_Line2->GetOutputPort());
m_RayLine->AddInputConnection(m_Sphere2->GetOutputPort());
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
Matrix4f mat = d->m_Content->GetImage()->GetWorldMatrix();
Matrix4f mat = m_Content->GetImage()->GetWorldMatrix();
for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j)
vmat->SetElement(i,j,mat(i,j));
d->m_Transform->SetMatrix(vmat);
m_Transform->SetMatrix(vmat);
this->SetRay(pt1,pt2);
}
@@ -237,22 +182,22 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca)
{
HPoint3f pt1,pt2,src;
src = muon.LineIn().origin;
d->m_Content->GetEntryPoint(muon.LineIn(),pt1);
d->m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2));
d->m_Line1->SetPoint1(src(0),src(1),src(2));
d->m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2));
m_Content->GetEntryPoint(muon.LineIn(),pt1);
m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2));
m_Line1->SetPoint1(src(0),src(1),src(2));
m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2));
HLine3f line_out = muon.LineOut();
src = line_out.origin;
float *direction = line_out.direction.data();
for(int i=0;i<3;++i) direction[i] *= -1;
d->m_Content->GetEntryPoint(line_out,pt2);
d->m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2));
d->m_Line2->SetPoint1(src(0),src(1),src(2));
d->m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2));
m_Content->GetEntryPoint(line_out,pt2);
m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2));
m_Line2->SetPoint1(src(0),src(1),src(2));
m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2));
d->m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2));
d->m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2));
m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2));
m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2));
// Create a vtkPoints object and store the points in it
vtkSmartPointer<vtkPoints> points =
@@ -284,34 +229,31 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca)
// Add the lines to the dataset
linesPolyData->SetLines(lines);
d->m_RayLine->RemoveAllInputs();
m_RayLine->RemoveAllInputs();
# if VTK_MAJOR_VERSION <= 5
d->m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
# else
d->m_RayLine->AddInputData(linesPolyData);
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
# endif
d->m_RayLine->AddInputConnection(d->m_Line1->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Sphere1->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Line2->GetOutputPort());
d->m_RayLine->AddInputConnection(d->m_Sphere2->GetOutputPort());
// d->m_RayLine->AddInputConnection(d->m_Line3->GetOutputPort());
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
m_RayLine->AddInputConnection(m_Line2->GetOutputPort());
m_RayLine->AddInputConnection(m_Sphere2->GetOutputPort());
vtkSmartPointer<vtkSphereSource> poca_sphere =
vtkSmartPointer<vtkSphereSource>::New();
poca_sphere->SetRadius(d->default_radius);
poca_sphere->SetRadius(default_radius);
poca_sphere->SetCenter(poca(0),poca(1),poca(2));
d->m_RayLine->AddInputConnection(poca_sphere->GetOutputPort());
m_RayLine->AddInputConnection(poca_sphere->GetOutputPort());
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
Matrix4f mat = d->m_Content->GetImage()->GetWorldMatrix();
Matrix4f mat = m_Content->GetImage()->GetWorldMatrix();
for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j)
vmat->SetElement(i,j,mat(i,j));
d->m_Transform->SetMatrix(vmat);
m_Transform->SetMatrix(vmat);
if(d->m_Content->GetImage()->IsInsideBounds(poca))
if(m_Content->GetImage()->IsInsideBounds(poca))
this->SetRay(pt1,poca,pt2);
else
this->SetRay(pt1,pt2);
@@ -328,38 +270,36 @@ void vtkVoxRaytracerRepresentation::SetMuon(vtkMuonScatter &muon)
VoxRaytracer::RayData vtkVoxRaytracerRepresentation::GetRay()
{
return d->m_Ray;
return m_Ray;
}
void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f out)
{
d->m_Ray = d->m_Content->TraceBetweenPoints(in,out);
this->SetRay(&d->m_Ray);
m_Ray = m_Content->TraceBetweenPoints(in,out);
this->SetRay(&m_Ray);
}
void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f mid, HPoint3f out)
{
d->m_Ray = d->m_Content->TraceBetweenPoints(in,mid);
d->m_Ray.AppendRay( d->m_Content->TraceBetweenPoints(mid,out) );
this->SetRay(&d->m_Ray);
m_Ray = m_Content->TraceBetweenPoints(in,mid);
m_Ray.AppendRay( m_Content->TraceBetweenPoints(mid,out) );
this->SetRay(&m_Ray);
}
void vtkVoxRaytracerRepresentation::SetRay(VoxRaytracer::RayData *ray)
{
vtkAppendPolyData *appender = d->m_RayRepresentation;
vtkAppendPolyData *appender = m_RayRepresentation;
appender->RemoveAllInputs();
for(int i=0; i<ray->Data().size(); ++i) {
int id = ray->Data().at(i).vox_id;
Vector3i idv = d->m_Content->GetImage()->UnMap(id);
Vector3i idv = m_Content->GetImage()->UnMap(id);
vtkSmartPointer<vtkCubeSource> cube =
vtkSmartPointer<vtkCubeSource>::New();
cube->SetBounds(idv(0),idv(0)+1,idv(1),idv(1)+1,idv(2),idv(2)+1);
cube->Update();
# if VTK_MAJOR_VERSION <= 5
appender->AddInput(cube->GetOutput());
# else
appender->AddInputData(cube->GetOutput());
# endif
appender->Update();
}
@@ -368,12 +308,12 @@ void vtkVoxRaytracerRepresentation::SetRay(VoxRaytracer::RayData *ray)
void vtkVoxRaytracerRepresentation::SetVoxelsColor(Vector4f rgba)
{
this->SetColor(d->m_RayRepresentationActor,rgba);
this->SetColor(m_RayRepresentationActor,rgba);
}
void vtkVoxRaytracerRepresentation::SetRayColor(Vector4f rgba)
{
this->SetColor(d->m_RayLineActor,rgba);
this->SetColor(m_RayLineActor,rgba);
}
void vtkVoxRaytracerRepresentation::SetColor(vtkActor *actor, Vector4f rgba)
@@ -395,10 +335,10 @@ void vtkVoxRaytracerRepresentation::InstallPipe()
vtkSmartPointer<vtkAppendPolyData> append =
vtkSmartPointer<vtkAppendPolyData>::New();
append->AddInputConnection(d->m_Sphere1->GetOutputPort());
append->AddInputConnection(d->m_Sphere2->GetOutputPort());
append->AddInputConnection(d->m_Line1->GetOutputPort());
append->AddInputConnection(d->m_Line2->GetOutputPort());
append->AddInputConnection(m_Sphere1->GetOutputPort());
append->AddInputConnection(m_Sphere2->GetOutputPort());
append->AddInputConnection(m_Line1->GetOutputPort());
append->AddInputConnection(m_Line2->GetOutputPort());
append->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
@@ -413,34 +353,24 @@ void vtkVoxRaytracerRepresentation::InstallPipe()
this->SetProp(actor);
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(d->m_RayLine->GetOutputPort());
mapper->SetInputConnection(m_RayLine->GetOutputPort());
mapper->Update();
d->m_RayLineActor->SetMapper(mapper);
d->m_RayLineActor->GetProperty()->SetColor(1,0,0);
this->SetProp(d->m_RayLineActor);
// mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
// mapper->SetInputConnection(d->m_Line3->GetOutputPort());
// mapper->Update();
// actor = vtkSmartPointer<vtkActor>::New();
// actor->SetMapper(mapper);
// actor->GetProperty()->SetColor(1,0,0);
// d->m_Assembly->AddPart(actor);
m_RayLineActor->SetMapper(mapper);
m_RayLineActor->GetProperty()->SetColor(1,0,0);
this->SetProp(m_RayLineActor);
vtkSmartPointer<vtkTransformPolyDataFilter> polyfilter =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
polyfilter->SetInputConnection(d->m_RayRepresentation->GetOutputPort());
polyfilter->SetTransform(d->m_Transform);
polyfilter->SetInputConnection(m_RayRepresentation->GetOutputPort());
polyfilter->SetTransform(m_Transform);
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polyfilter->GetOutputPort());
mapper->Update();
vtkActor *vra = d->m_RayRepresentationActor;
vtkActor *vra = m_RayRepresentationActor;
vra->SetMapper(mapper);
vra->GetProperty()->SetOpacity(0.2);
vra->GetProperty()->SetEdgeVisibility(true);