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

@@ -28,7 +28,6 @@
#ifndef U_HITMC_H #ifndef U_HITMC_H
#define U_HITMC_H #define U_HITMC_H
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
#include "Hit.h" #include "Hit.h"
@@ -43,10 +42,10 @@ public:
DeltaRay DeltaRay
}; };
uLibConstRefMacro(Position,HPoint3f) inline const HPoint3f & Position() const { return this->m_Position; }
uLibGetMacro(Type, enum Type) inline enum Type GetType() const { return this->m_Type; }
private: protected:
HPoint3f m_Position; HPoint3f m_Position;
enum Type m_Type; enum Type m_Type;
}; };
@@ -54,8 +53,8 @@ private:
class HitMC : public HitMCData { class HitMC : public HitMCData {
public: public:
uLibRefMacro(Position,HPoint3f) inline HPoint3f & Position() { return this->m_Position; }
uLibSetMacro(Type, enum Type) inline void SetType(enum Type name) { this->m_Type = name; }
}; };

View File

@@ -28,7 +28,6 @@
#ifndef U_LINEARFIT_H #ifndef U_LINEARFIT_H
#define U_LINEARFIT_H #define U_LINEARFIT_H
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
#include "ChamberDetector.h" #include "ChamberDetector.h"
@@ -37,32 +36,31 @@ namespace uLib {
class LinearFitData { class LinearFitData {
public: public:
uLibConstRefMacro(Position,Vector2f) inline const Vector2f & Position() const { return this->m_Position; }
uLibConstRefMacro(Slope,Vector2f) inline const Vector2f & Slope() const { return this->m_Slope; }
uLibConstRefMacro(PositionError,Vector2f) inline const Vector2f & PositionError() const { return this->m_PositionError; }
uLibConstRefMacro(SlopeError,Vector2f) inline const Vector2f & SlopeError() const { return this->m_SlopeError; }
uLibGetMacro(HitsNumber,int) inline int GetHitsNumber() const { return this->m_HitsNumber; }
uLibGetMacro(Idv,ChamberDetector::ID) inline ChamberDetector::ID GetIdv() const { return this->m_Idv; }
private: protected:
friend class LinearFit; Vector2f m_Position;
Vector2f m_Position; Vector2f m_Slope;
Vector2f m_Slope; Vector2f m_PositionError;
Vector2f m_PositionError; Vector2f m_SlopeError;
Vector2f m_SlopeError; int m_HitsNumber;
int m_HitsNumber;
DetectorChamber::ID m_Idv; DetectorChamber::ID m_Idv;
}; };
class LinearFit : public LinearFitData { class LinearFit : public LinearFitData {
public: public:
uLibRefMacro(Position,Vector2f) inline Vector2f & Position() { return this->m_Position; }
uLibRefMacro(Slope,Vector2f) inline Vector2f & Slope() { return this->m_Slope; }
uLibRefMacro(PositionError,Vector2f) inline Vector2f & PositionError() { return this->m_PositionError; }
uLibRefMacro(SlopeError,Vector2f) inline Vector2f & SlopeError() { return this->m_SlopeError; }
uLibSetMacro(HitsNumber,int) inline void SetHitsNumber(int name) { this->m_HitsNumber = name; }
uLibSetMacro(Idv,ChamberDetector::ID) inline void SetIdv(ChamberDetector::ID name) { this->m_Idv = name; }
}; };

View File

@@ -28,18 +28,16 @@
#ifndef U_MUONERROR_H #ifndef U_MUONERROR_H
#define U_MUONERROR_H #define U_MUONERROR_H
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
namespace uLib { namespace uLib {
class MuonErrorData { class MuonErrorData {
friend class MuonError;
public: public:
uLibConstRefMacro(Theta,Scalarf) inline const Scalarf & Theta() const { return this->m_Theta; }
uLibConstRefMacro(Phi,Scalarf) inline const Scalarf & Phi() const { return this->m_Phi; }
private: protected:
Scalarf m_Theta; Scalarf m_Theta;
Scalarf m_Phi; Scalarf m_Phi;
}; };
@@ -47,8 +45,8 @@ private:
class MuonError : public MuonErrorData { class MuonError : public MuonErrorData {
public: public:
uLibRefMacro(Theta,Scalarf) inline Scalarf & Theta() { return this->m_Theta; }
uLibRefMacro(Phi,Scalarf) inline Scalarf & Phi() { return this->m_Phi; }
}; };

View File

@@ -28,20 +28,18 @@
#ifndef U_MUONEVENT_H #ifndef U_MUONEVENT_H
#define U_MUONEVENT_H #define U_MUONEVENT_H
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
namespace uLib { namespace uLib {
class MuonEventData { class MuonEventData {
friend class MuonEvent;
public: public:
uLibConstRefMacro(LineIn,HLine3f) inline const HLine3f & LineIn() const { return this->m_LineIn; }
uLibConstRefMacro(LineOut,HLine3f) inline const HLine3f & LineOut() const { return this->m_LineOut; }
uLibGetMacro(Momentum,Scalarf) inline Scalarf GetMomentum() const { return this->m_Momentum; }
private: protected:
HLine3f m_LineIn; HLine3f m_LineIn;
HLine3f m_LineOut; HLine3f m_LineOut;
Scalarf m_Momentum; Scalarf m_Momentum;
@@ -50,9 +48,9 @@ private:
class MuonEvent : public MuonEventData { class MuonEvent : public MuonEventData {
public: public:
uLibRefMacro(LineIn,HLine3f) inline HLine3f & LineIn() { return this->m_LineIn; }
uLibRefMacro(LineOut,HLine3f) inline HLine3f & LineOut() { return this->m_LineOut; }
uLibRefMacro(Momentum,Scalarf) inline Scalarf & Momentum() { return this->m_Momentum; }
}; };

View File

@@ -29,7 +29,6 @@
#ifndef U_MUONSCATTER_H #ifndef U_MUONSCATTER_H
#define U_MUONSCATTER_H #define U_MUONSCATTER_H
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
namespace uLib { namespace uLib {
@@ -37,20 +36,21 @@ namespace uLib {
class MuonScatter { class MuonScatter {
public: public:
uLibConstRefMacro(LineIn,HLine3f) inline const HLine3f & LineIn() const { return this->m_LineIn; }
uLibConstRefMacro(ErrorIn,HError3f) inline const HError3f & ErrorIn() const { return this->m_ErrorIn; }
uLibConstRefMacro(LineOut,HLine3f) inline const HLine3f & LineOut() const { return this->m_LineOut; }
uLibConstRefMacro(ErrorOut,HError3f) inline const HError3f & ErrorOut() const { return this->m_ErrorOut; }
uLibRefMacro(LineIn,HLine3f) inline HLine3f & LineIn() { return this->m_LineIn; }
uLibRefMacro(ErrorIn,HError3f) inline HError3f & ErrorIn() { return this->m_ErrorIn; }
uLibRefMacro(LineOut,HLine3f) inline HLine3f & LineOut() { return this->m_LineOut; }
uLibRefMacro(ErrorOut,HError3f) inline HError3f & ErrorOut() { return this->m_ErrorOut; }
uLibSetMacro(Momentum,Scalarf)
uLibSetMacro(MomentumPrime,Scalarf)
uLibGetMacro(Momentum,Scalarf) inline void SetMomentum(Scalarf name) { this->m_Momentum = name; }
uLibGetMacro(MomentumPrime,Scalarf) inline void SetMomentumPrime(Scalarf name) { this->m_MomentumPrime = name; }
inline Scalarf GetMomentum() const { return this->m_Momentum; }
inline Scalarf GetMomentumPrime() const { return this->m_MomentumPrime; }
protected: protected:
HLine3f m_LineIn; HLine3f m_LineIn;

View File

@@ -28,7 +28,6 @@
#ifndef STRUCTUREDDATA_H #ifndef STRUCTUREDDATA_H
#define STRUCTUREDDATA_H #define STRUCTUREDDATA_H
#include "Core/Macros.h"
#include "Core/Object.h" #include "Core/Object.h"
#include "Math/Dense.h" #include "Math/Dense.h"
@@ -60,15 +59,17 @@ public:
{} {}
uLibGetMacro(Dims,Vector3i) inline Vector3i GetDims() const { return this->m_Dims; }
void SetDims(const Vector3i &size); void SetDims(const Vector3i &size);
uLibGetSetMacro(Increments,Vector3i) inline Vector3i GetIncrements() const { return this->m_Increments; }
inline void SetIncrements(Vector3i name) { this->m_Increments = name; }
void SetDataOrder(Order order = YXZ); void SetDataOrder(Order order = YXZ);
uLibGetMacro(DataOrder,Order) inline Order GetDataOrder() const { return this->m_DataOrder; }
bool IsInsideGrid(const Vector3i &v) const; bool IsInsideGrid(const Vector3i &v) const;

View File

@@ -25,31 +25,30 @@
/* /*
* Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it> * Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as * it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the * published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, but * This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA * 02110-1301 USA
* *
*/ */
#ifndef U_TRANSFORM_H #ifndef U_TRANSFORM_H
#define U_TRANSFORM_H #define U_TRANSFORM_H
#include <Core/Macros.h>
#include <Eigen/Geometry> #include <Eigen/Geometry>
@@ -80,7 +79,10 @@ public:
{} {}
Eigen::Affine3f& GetTransform() { return m_T; } Eigen::Affine3f& GetTransform() { return m_T; }
uLibGetSetMacro(Parent,AffineTransform *)
inline AffineTransform *GetParent() const { return this->m_Parent; }
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; } inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; }
inline Matrix4f& GetMatrix () { return m_T.matrix(); } inline Matrix4f& GetMatrix () { return m_T.matrix(); }

View File

@@ -30,7 +30,6 @@
#include "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
#include "uLibVtkInterface.h" #include "uLibVtkInterface.h"
@@ -66,8 +65,6 @@ protected:
private: private:
void InstallPipe(); void InstallPipe();
friend class vtkMuonContainerScatteringPimpl;
class vtkMuonContainerScatteringPimpl *d;
}; };

View File

@@ -29,22 +29,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include <vtkActor.h>
#include <vtk3DWidget.h>
#include <vtkBoxWidget.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkTransform.h>
#include "vtkMuonEvent.h" #include "vtkMuonEvent.h"
#include "Math/Dense.h" #include "Math/Dense.h"
@@ -72,105 +56,77 @@ private:
}; };
//// PIMPL /////////////////////////////////////////////////////////////////////
class vtkMuonEventPimpl {
typedef vtkWidgetCallback Callback;
public:
vtkMuonEventPimpl() :
m_Prop(vtkActor::New()),
m_PolyData(NULL),
m_Appender(vtkAppendPolyData::New()),
content(NULL)
{}
~vtkMuonEventPimpl()
{
m_Prop->Delete();
}
// members //
vtkMuonEvent::Content *content;
vtkPolyData *m_PolyData;
vtkActor *m_Prop;
vtkAppendPolyData *m_Appender;
vtkBoxWidget *m_WidgetIN, *m_WidgetOUT;
HPoint3f m_Poca;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VTK MUON EVENT ///////////////////////////////////////////////////////// ///// VTK MUON EVENT /////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
vtkMuonEvent::vtkMuonEvent(MuonEventData &content) : vtkMuonEvent::vtkMuonEvent(MuonEventData &content) :
d(new vtkMuonEventPimpl) m_Prop(vtkActor::New()),
m_PolyData(NULL),
m_Appender(vtkAppendPolyData::New()),
content(&content)
{ {
d->content = &content; InstallPipe();
InstallPipe();
} }
vtkMuonEvent::vtkMuonEvent(const MuonEventData &content) : vtkMuonEvent::vtkMuonEvent(const MuonEventData &content) :
d(new vtkMuonEventPimpl) m_Prop(vtkActor::New()),
m_PolyData(NULL),
m_Appender(vtkAppendPolyData::New()),
content(const_cast<MuonEventData *>(&content))
{ {
d->content = const_cast<MuonEventData *>(&content); InstallPipe();
InstallPipe();
} }
vtkMuonEvent::~vtkMuonEvent() vtkMuonEvent::~vtkMuonEvent()
{ {
if (d->m_Prop) d->m_Prop->Delete(); if (m_Prop) m_Prop->Delete();
} }
vtkMuonEvent::Content &vtkMuonEvent::GetContent() vtkMuonEvent::Content &vtkMuonEvent::GetContent()
{ {
return *d->content; return *content;
} }
void vtkMuonEvent::PrintSelf(std::ostream &o) const void vtkMuonEvent::PrintSelf(std::ostream &o) const
{ {
o << "..:: MuonEvent ::..\n" \ o << "..:: MuonEvent ::..\n" \
"\t[in] Origin > " << d->content->LineIn().origin.transpose() << "\n" << "\t[in] Origin > " << content->LineIn().origin.transpose() << "\n" <<
"\t[in] Direction > " << d->content->LineIn().direction.transpose() << "\n" << "\t[in] Direction > " << content->LineIn().direction.transpose() << "\n" <<
"\t[out] Origin > " << d->content->LineOut().origin.transpose() << "\n" << "\t[out] Origin > " << content->LineOut().origin.transpose() << "\n" <<
"\t[out] Direction > " << d->content->LineOut().direction.transpose()<< "\n" << "\t[out] Direction > " << content->LineOut().direction.transpose()<< "\n" <<
"\tMomentum > " << d->content->GetMomentum() << "\n" << "\tMomentum > " << content->GetMomentum() << "\n" <<
"...................\n"; "...................\n";
} }
vtkProp *vtkMuonEvent::GetProp() vtkProp *vtkMuonEvent::GetProp()
{ {
return d->m_Prop; return m_Prop;
} }
void vtkMuonEvent::InstallPipe() void vtkMuonEvent::InstallPipe()
{ {
vtkAppendPolyData *appender = d->m_Appender; vtkAppendPolyData *appender = m_Appender;
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
if(d->content) { if(content) {
vtkSmartPointer<vtkLineSource> line_in = vtkSmartPointer<vtkLineSource>::New(); vtkSmartPointer<vtkLineSource> line_in = vtkSmartPointer<vtkLineSource>::New();
vtkSmartPointer<vtkLineSource> line_out = vtkSmartPointer<vtkLineSource>::New(); vtkSmartPointer<vtkLineSource> line_out = vtkSmartPointer<vtkLineSource>::New();
float distance = (d->content->LineIn().origin - d->content->LineOut().origin).norm() / 10; float distance = (content->LineIn().origin - content->LineOut().origin).norm() / 10;
HPoint3f pt; HPoint3f pt;
pt = d->content->LineIn().origin; pt = content->LineIn().origin;
line_in->SetPoint1(pt(0),pt(1),pt(2)); line_in->SetPoint1(pt(0),pt(1),pt(2));
pt= d->content->LineIn().origin + d->content->LineIn().direction * distance; pt= content->LineIn().origin + content->LineIn().direction * distance;
line_in->SetPoint2(pt(0),pt(1),pt(2)); line_in->SetPoint2(pt(0),pt(1),pt(2));
pt = d->content->LineOut().origin; pt = content->LineOut().origin;
line_out->SetPoint1(pt(0),pt(1),pt(2)); line_out->SetPoint1(pt(0),pt(1),pt(2));
pt = d->content->LineOut().origin + d->content->LineOut().direction * distance; pt = content->LineOut().origin + content->LineOut().direction * distance;
line_out->SetPoint2(pt(0),pt(1),pt(2)); line_out->SetPoint2(pt(0),pt(1),pt(2));
appender->AddInputConnection(line_in->GetOutputPort()); appender->AddInputConnection(line_in->GetOutputPort());
@@ -180,31 +136,31 @@ void vtkMuonEvent::InstallPipe()
appender->Update(); appender->Update();
mapper->SetInputConnection(appender->GetOutputPort()); mapper->SetInputConnection(appender->GetOutputPort());
mapper->Update(); mapper->Update();
d->m_Prop->SetMapper(mapper); m_Prop->SetMapper(mapper);
} }
vtkPolyData *vtkMuonEvent::GetPolyData() const vtkPolyData *vtkMuonEvent::GetPolyData() const
{ {
return d->m_Appender->GetOutput(); return m_Appender->GetOutput();
} }
void vtkMuonEvent::AddPocaPoint(HPoint3f poca) void vtkMuonEvent::AddPocaPoint(HPoint3f poca)
{ {
d->m_Poca = poca; m_Poca = poca;
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource> sphere =
vtkSmartPointer<vtkSphereSource>::New(); vtkSmartPointer<vtkSphereSource>::New();
float size = (d->content->LineIn().origin - d->content->LineOut().origin).head(3).norm(); float size = (content->LineIn().origin - content->LineOut().origin).head(3).norm();
size /= 100; size /= 100;
sphere->SetRadius(size); sphere->SetRadius(size);
sphere->SetCenter(poca(0),poca(1),poca(2)); sphere->SetCenter(poca(0),poca(1),poca(2));
sphere->Update(); sphere->Update();
d->m_Appender->AddInputConnection(sphere->GetOutputPort()); m_Appender->AddInputConnection(sphere->GetOutputPort());
d->m_Appender->Update(); m_Appender->Update();
} }
HPoint3f vtkMuonEvent::GetPocaPoint() HPoint3f vtkMuonEvent::GetPocaPoint()
{ {
return d->m_Poca; return m_Poca;
} }

View File

@@ -28,7 +28,21 @@
#ifndef VTKMUONEVENT_H #ifndef VTKMUONEVENT_H
#define VTKMUONEVENT_H #define VTKMUONEVENT_H
#include "Core/Macros.h" #include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include <vtkActor.h>
#include <vtk3DWidget.h>
#include <vtkBoxWidget.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkTransform.h>
#include "Math/Dense.h" #include "Math/Dense.h"
#include "uLibVtkInterface.h" #include "uLibVtkInterface.h"
@@ -64,8 +78,14 @@ public:
private: private:
void InstallPipe(); void InstallPipe();
friend class vtkMuonEventPimpl; vtkMuonEvent::Content *content;
class vtkMuonEventPimpl *d; vtkPolyData *m_PolyData;
vtkActor *m_Prop;
vtkAppendPolyData *m_Appender;
vtkBoxWidget *m_WidgetIN;
vtkBoxWidget *m_WidgetOUT;
HPoint3f m_Poca;
}; };

View File

@@ -30,23 +30,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <vtkConfigure.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include <vtkActor.h>
#include <vtk3DWidget.h>
#include <vtkBoxWidget.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkTransform.h>
#include "vtkMuonScatter.h" #include "vtkMuonScatter.h"
#include "Math/Dense.h" #include "Math/Dense.h"
@@ -78,36 +61,6 @@ namespace Vtk {
//} //}
//// PIMPL /////////////////////////////////////////////////////////////////////
class vtkMuonScatterPimpl {
public:
vtkMuonScatterPimpl() :
m_Content(NULL),
m_LineIn(vtkLineSource::New()),
m_LineOut(vtkLineSource::New()),
m_PolyData(vtkPolyData::New()),
m_SpherePoca(NULL)
{}
~vtkMuonScatterPimpl()
{
m_LineIn->Delete();
m_LineOut->Delete();
if(m_SpherePoca) m_SpherePoca->Delete();
}
// members //
vtkMuonScatter::Content *m_Content;
vtkLineSource *m_LineIn, *m_LineOut;
vtkSphereSource *m_SpherePoca;
vtkPolyData *m_PolyData;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VTK MUON Scatter ///////////////////////////////////////////////////////// ///// VTK MUON Scatter /////////////////////////////////////////////////////////
@@ -115,63 +68,69 @@ public:
vtkMuonScatter::vtkMuonScatter(MuonScatter &content) : vtkMuonScatter::vtkMuonScatter(MuonScatter &content) :
d(new vtkMuonScatterPimpl) m_Content(&content),
m_LineIn(vtkLineSource::New()),
m_LineOut(vtkLineSource::New()),
m_PolyData(vtkPolyData::New()),
m_SpherePoca(NULL)
{ {
d->m_Content = &content; InstallPipe();
InstallPipe();
} }
vtkMuonScatter::vtkMuonScatter(const MuonScatter &content) : vtkMuonScatter::vtkMuonScatter(const MuonScatter &content) :
d(new vtkMuonScatterPimpl) m_Content(const_cast<MuonScatter *>(&content)),
m_LineIn(vtkLineSource::New()),
m_LineOut(vtkLineSource::New()),
m_PolyData(vtkPolyData::New()),
m_SpherePoca(NULL)
{ {
d->m_Content = const_cast<MuonScatter *>(&content); InstallPipe();
InstallPipe();
} }
vtkMuonScatter::~vtkMuonScatter() vtkMuonScatter::~vtkMuonScatter()
{ {
delete d; m_LineIn->Delete();
m_LineOut->Delete();
if(m_SpherePoca) m_SpherePoca->Delete();
} }
vtkMuonScatter::Content &vtkMuonScatter::GetContent() vtkMuonScatter::Content &vtkMuonScatter::GetContent()
{ {
return *d->m_Content; return *m_Content;
} }
void vtkMuonScatter::PrintSelf(std::ostream &o) const void vtkMuonScatter::PrintSelf(std::ostream &o) const
{ {}
// o << d->content;
}
void vtkMuonScatter::InstallPipe() void vtkMuonScatter::InstallPipe()
{ {
if(d->m_Content) { if(m_Content) {
vtkLineSource *line_in = d->m_LineIn; vtkLineSource *line_in = m_LineIn;
vtkLineSource *line_out = d->m_LineOut; vtkLineSource *line_out = m_LineOut;
float distance = (d->m_Content->LineIn().origin - d->m_Content->LineOut().origin).norm() / 10; float distance = (m_Content->LineIn().origin - m_Content->LineOut().origin).norm() / 10;
HPoint3f pt; HPoint3f pt;
pt = d->m_Content->LineIn().origin; pt = m_Content->LineIn().origin;
line_in->SetPoint1(pt(0),pt(1),pt(2)); line_in->SetPoint1(pt(0),pt(1),pt(2));
pt= d->m_Content->LineIn().origin + d->m_Content->LineIn().direction * distance; pt= m_Content->LineIn().origin + m_Content->LineIn().direction * distance;
line_in->SetPoint2(pt(0),pt(1),pt(2)); line_in->SetPoint2(pt(0),pt(1),pt(2));
pt = d->m_Content->LineOut().origin; pt = m_Content->LineOut().origin;
line_out->SetPoint1(pt(0),pt(1),pt(2)); line_out->SetPoint1(pt(0),pt(1),pt(2));
pt = d->m_Content->LineOut().origin + d->m_Content->LineOut().direction * distance; pt = m_Content->LineOut().origin + m_Content->LineOut().direction * distance;
line_out->SetPoint2(pt(0),pt(1),pt(2)); line_out->SetPoint2(pt(0),pt(1),pt(2));
} }
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(d->m_LineIn->GetOutputPort()); mapper->SetInputConnection(m_LineIn->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
this->SetProp(actor); this->SetProp(actor);
mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(d->m_LineOut->GetOutputPort()); mapper->SetInputConnection(m_LineOut->GetOutputPort());
actor = vtkSmartPointer<vtkActor>::New(); actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
this->SetProp(actor); this->SetProp(actor);
@@ -180,32 +139,26 @@ void vtkMuonScatter::InstallPipe()
vtkPolyData *vtkMuonScatter::GetPolyData() const vtkPolyData *vtkMuonScatter::GetPolyData() const
{ {
vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New(); vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New();
//# if VTK_MAJOR_VERSION <= 5 append->AddInputConnection(m_LineIn->GetOutputPort());
append->AddInputConnection(d->m_LineIn->GetOutputPort()); append->AddInputConnection(m_LineOut->GetOutputPort());
append->AddInputConnection(d->m_LineOut->GetOutputPort()); if(m_SpherePoca) append->AddInputConnection(m_SpherePoca->GetOutputPort());
if(d->m_SpherePoca) append->AddInputConnection(d->m_SpherePoca->GetOutputPort());
//# else
// append->AddInputData(d->m_LineIn->GetOutput());
// append->AddInputData(d->m_LineOut->GetOutput());
// if(d->m_SpherePoca) append->AddInputData(d->m_SpherePoca->GetOutput());
//# endif
append->Update(); append->Update();
d->m_PolyData->DeepCopy(append->GetOutput()); m_PolyData->DeepCopy(append->GetOutput());
return d->m_PolyData; return m_PolyData;
} }
void vtkMuonScatter::AddPocaPoint(HPoint3f poca) void vtkMuonScatter::AddPocaPoint(HPoint3f poca)
{ {
vtkSphereSource *sphere = vtkSphereSource::New(); vtkSphereSource *sphere = vtkSphereSource::New();
float size = (d->m_Content->LineIn().origin - d->m_Content->LineOut().origin).head(3).norm(); float size = (m_Content->LineIn().origin - m_Content->LineOut().origin).head(3).norm();
size /= 100; size /= 100;
sphere->SetRadius(size); sphere->SetRadius(size);
sphere->SetCenter(poca(0),poca(1),poca(2)); sphere->SetCenter(poca(0),poca(1),poca(2));
sphere->Update(); sphere->Update();
d->m_SpherePoca = sphere; m_SpherePoca = sphere;
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(d->m_SpherePoca->GetOutputPort()); mapper->SetInputConnection(m_SpherePoca->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
this->SetProp(actor); this->SetProp(actor);
@@ -214,8 +167,8 @@ void vtkMuonScatter::AddPocaPoint(HPoint3f poca)
HPoint3f vtkMuonScatter::GetPocaPoint() HPoint3f vtkMuonScatter::GetPocaPoint()
{ {
double center[3]; double center[3];
if(d->m_SpherePoca) { if(m_SpherePoca) {
d->m_SpherePoca->GetCenter(center); m_SpherePoca->GetCenter(center);
return HPoint3f(center[0],center[1],center[2]); return HPoint3f(center[0],center[1],center[2]);
} }
else { else {

View File

@@ -28,7 +28,22 @@
#ifndef VTKMUONSCATTER_H #ifndef VTKMUONSCATTER_H
#define VTKMUONSCATTER_H #define VTKMUONSCATTER_H
#include "Core/Macros.h" #include <vtkConfigure.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include <vtkActor.h>
#include <vtk3DWidget.h>
#include <vtkBoxWidget.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkTransform.h>
#include "Math/Dense.h" #include "Math/Dense.h"
#include "uLibVtkInterface.h" #include "uLibVtkInterface.h"
@@ -66,8 +81,11 @@ protected:
private: private:
void InstallPipe(); void InstallPipe();
friend class vtkMuonScatterPimpl; vtkMuonScatter::Content *m_Content;
class vtkMuonScatterPimpl *d; vtkLineSource *m_LineIn;
vtkLineSource *m_LineOut;
vtkSphereSource *m_SpherePoca;
vtkPolyData *m_PolyData;
}; };
} // vtk } // vtk

View File

@@ -29,82 +29,12 @@
#include "config.h" #include "config.h"
#endif #endif
#include <vtkLineSource.h>
#include <vtkBoundingBox.h>
#include <vtkCubeSource.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkBoxWidget.h>
#include <vtkCommand.h>
#include "Math/StructuredGrid.h" #include "Math/StructuredGrid.h"
#include "Vtk/vtkStructuredGrid.h" #include "Vtk/vtkStructuredGrid.h"
namespace uLib { namespace uLib {
namespace Vtk { namespace Vtk {
////////////////////////////////////////////////////////////////////////////////
////// PIMPL //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class vtkStructuredGridPimpl {
// ---- WIDGET CBK ------------------------------------------------------ //
class vtkWidgetCallback : public vtkCommand
{
public:
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
void SetParent(uLib::Vtk::vtkStructuredGrid *parent) { this->parent = parent; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkSmartPointer<vtkTransform> t =
vtkSmartPointer<vtkTransform>::New();
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
parent->SetTransform(t);
//std::cout << "event\n";
}
private:
uLib::Vtk::vtkStructuredGrid *parent;
};
// ---------------------------------------------------------------------- //
public:
vtkStructuredGridPimpl(vtkStructuredGrid *parent, StructuredGrid &content) :
p(parent),
m_Content(&content),
m_Actor(vtkActor::New()),
m_Widget(vtkBoxWidget::New()),
m_Transform(vtkTransform::New())
{
vtkSmartPointer<vtkWidgetCallback> callback =
vtkSmartPointer<vtkWidgetCallback>::New();
callback->SetParent(p);
m_Widget->AddObserver(vtkCommand::InteractionEvent, callback);
}
~vtkStructuredGridPimpl()
{
m_Actor->Delete();
m_Widget->Delete();
m_Transform->Delete();
}
// members //
vtkActor *m_Actor;
vtkBoxWidget *m_Widget;
StructuredGrid *m_Content;
vtkTransform *m_Transform;
private:
vtkStructuredGrid *p;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////// VTK STRUCTURED GRID ///////////////////////////////////////////////////// ////// VTK STRUCTURED GRID /////////////////////////////////////////////////////
@@ -113,14 +43,24 @@ private:
vtkStructuredGrid::vtkStructuredGrid(Content &content) : vtkStructuredGrid::vtkStructuredGrid(Content &content) :
d(new vtkStructuredGridPimpl(this,content)) m_Content(&content),
m_Actor(vtkActor::New()),
m_Widget(vtkBoxWidget::New()),
m_Transform(vtkTransform::New())
{ {
vtkSmartPointer<vtkWidgetCallback> callback =
vtkSmartPointer<vtkWidgetCallback>::New();
callback->SetGrid(this);
m_Widget->AddObserver(vtkCommand::InteractionEvent, callback);
this->InstallPipe(); this->InstallPipe();
} }
vtkStructuredGrid::~vtkStructuredGrid() vtkStructuredGrid::~vtkStructuredGrid()
{ {
delete d; m_Actor->Delete();
m_Widget->Delete();
m_Transform->Delete();
} }
@@ -131,26 +71,26 @@ void vtkStructuredGrid::SetTransform(vtkTransform *t)
for(int i=0; i<4; ++i) for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j) for(int j=0; j<4; ++j)
mat(i,j) = vmat->GetElement(i,j); mat(i,j) = vmat->GetElement(i,j);
d->m_Content->SetMatrix(mat); m_Content->SetMatrix(mat);
vtkSmartPointer<vtkMatrix4x4> vmat2 = vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4> vmat2 = vtkSmartPointer<vtkMatrix4x4>::New();
mat = d->m_Content->GetWorldMatrix(); mat = m_Content->GetWorldMatrix();
for(int i=0; i<4; ++i) for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j) for(int j=0; j<4; ++j)
vmat2->SetElement(i,j,mat(i,j)); vmat2->SetElement(i,j,mat(i,j));
d->m_Transform->SetMatrix(vmat2); m_Transform->SetMatrix(vmat2);
d->m_Transform->Update(); m_Transform->Update();
this->Update(); this->Update();
} }
vtkBoxWidget *vtkStructuredGrid::GetWidget() vtkBoxWidget *vtkStructuredGrid::GetWidget()
{ {
return d->m_Widget; return m_Widget;
} }
void vtkStructuredGrid::Update() void vtkStructuredGrid::Update()
{ {
d->m_Actor->GetMapper()->Update(); m_Actor->GetMapper()->Update();
} }
void vtkStructuredGrid::InstallPipe() void vtkStructuredGrid::InstallPipe()
@@ -161,15 +101,15 @@ void vtkStructuredGrid::InstallPipe()
vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter>::New();
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
Matrix4f mat = d->m_Content->GetWorldMatrix(); Matrix4f mat = m_Content->GetWorldMatrix();
for(int i=0; i<4; ++i) for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j) for(int j=0; j<4; ++j)
vmat->SetElement(i,j,mat(i,j)); vmat->SetElement(i,j,mat(i,j));
d->m_Transform->SetMatrix(vmat); m_Transform->SetMatrix(vmat);
filter->SetTransform(d->m_Transform); filter->SetTransform(m_Transform);
filter->SetInputConnection(cube->GetOutputPort()); filter->SetInputConnection(cube->GetOutputPort());
Vector3i dims = d->m_Content->GetDims(); Vector3i dims = m_Content->GetDims();
cube->SetBounds(0,dims(0),0,dims(1),0,dims(2)); cube->SetBounds(0,dims(0),0,dims(1),0,dims(2));
cube->Update(); cube->Update();
filter->Update(); filter->Update();
@@ -178,16 +118,16 @@ void vtkStructuredGrid::InstallPipe()
vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(filter->GetOutputPort()); mapper->SetInputConnection(filter->GetOutputPort());
d->m_Actor->SetMapper(mapper); m_Actor->SetMapper(mapper);
d->m_Actor->GetProperty()->SetRepresentationToSurface(); m_Actor->GetProperty()->SetRepresentationToSurface();
d->m_Actor->GetProperty()->SetEdgeVisibility(true); m_Actor->GetProperty()->SetEdgeVisibility(true);
d->m_Actor->GetProperty()->SetOpacity(0.4); m_Actor->GetProperty()->SetOpacity(0.4);
d->m_Actor->GetProperty()->SetAmbient(0.7); m_Actor->GetProperty()->SetAmbient(0.7);
// set content transform to actor // // set content transform to actor //
this->Update(); this->Update();
d->m_Widget->SetProp3D(d->m_Actor); m_Widget->SetProp3D(m_Actor);
this->SetProp(d->m_Actor); this->SetProp(m_Actor);
} }

View File

@@ -28,7 +28,19 @@
#ifndef U_VTKSTRUCTUREDGRID_H #ifndef U_VTKSTRUCTUREDGRID_H
#define U_VTKSTRUCTUREDGRID_H #define U_VTKSTRUCTUREDGRID_H
#include "Core/Macros.h" #include <vtkLineSource.h>
#include <vtkBoundingBox.h>
#include <vtkCubeSource.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkBoxWidget.h>
#include <vtkCommand.h>
#include "Math/Dense.h" #include "Math/Dense.h"
#include "uLibVtkInterface.h" #include "uLibVtkInterface.h"
@@ -55,8 +67,28 @@ public:
private: private:
void InstallPipe(); void InstallPipe();
friend class vtkStructuredGridPimpl; class vtkWidgetCallback : public vtkCommand
class vtkStructuredGridPimpl *d; {
public:
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
void SetGrid(uLib::Vtk::vtkStructuredGrid *grid) { this->grid = grid; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
grid->SetTransform(t);
}
private:
uLib::Vtk::vtkStructuredGrid *grid;
};
vtkActor *m_Actor;
vtkBoxWidget *m_Widget;
StructuredGrid *m_Content;
vtkTransform *m_Transform;
}; };

View File

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

View File

@@ -28,8 +28,24 @@
#ifndef U_VTKVOXRAYTRACERREPRESENTATION_H #ifndef U_VTKVOXRAYTRACERREPRESENTATION_H
#define U_VTKVOXRAYTRACERREPRESENTATION_H #define U_VTKVOXRAYTRACERREPRESENTATION_H
#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 "Core/Macros.h"
#include "Math/Dense.h" #include "Math/Dense.h"
#include "uLibVtkInterface.h" #include "uLibVtkInterface.h"
@@ -89,8 +105,23 @@ private:
void SetColor(vtkActor *actor, Vector4f rgba); void SetColor(vtkActor *actor, Vector4f rgba);
friend class vtkVoxRaytracerRepresentationPimpl; VoxRaytracer *m_Content;
class vtkVoxRaytracerRepresentationPimpl *d;
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;
vtkSmartPointer<vtkSphereSource> m_Sphere2;
vtkSmartPointer<vtkLineSource> m_Line1;
vtkSmartPointer<vtkLineSource> m_Line2;
vtkSmartPointer<vtkLineSource> m_Line3;
vtkSmartPointer<vtkAppendPolyData> m_RayRepresentation;
vtkAppendPolyData *m_SelectedElement;
}; };