vvSlicer.cxx
vvLandmarks.cxx
vvLandmarksGlyph.cxx
+ vvClipPolyData.cxx
vvGlyphSource.cxx
vvGlyph2D.cxx
vvSlicerManager.cxx
--- /dev/null
+#include "vvClipPolyData.h"
+
+#include "vtkObjectFactory.h"
+#include "vtkStreamingDemandDrivenPipeline.h"
+#include "vtkInformationVector.h"
+#include "vtkInformation.h"
+#include "vtkDataObject.h"
+#include "vtkSmartPointer.h"
+#include "vtkImplicitFunction.h"
+#include "vtkStringArray.h"
+#include "vtkPointData.h"
+
+
+vtkStandardNewMacro(vvClipPolyData);
+
+vvClipPolyData::vvClipPolyData()
+{
+ this->SetNumberOfInputPorts(1);
+ this->SetNumberOfOutputPorts(1);
+}
+
+vvClipPolyData::~vvClipPolyData()
+{
+
+}
+
+int vvClipPolyData::RequestData(vtkInformation *vtkNotUsed(request),
+ vtkInformationVector **inputVector,
+ vtkInformationVector *outputVector)
+{
+ // get the info objects
+ vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
+ vtkInformation *outInfo = outputVector->GetInformationObject(0);
+ // get the input and ouptut
+ vtkPolyData *input = vtkPolyData::SafeDownCast(
+ inInfo->Get(vtkDataObject::DATA_OBJECT()));
+ vtkStringArray* inputLabels = vtkStringArray::SafeDownCast(input->GetPointData()->GetAbstractArray("labels"));
+ vtkPolyData *output = vtkPolyData::SafeDownCast(
+ outInfo->Get(vtkDataObject::DATA_OBJECT()));
+ //
+ vtkImplicitFunction* currentImpliciteFunction = this->GetClipFunction();
+ int insideOutValue = this->GetInsideOut();
+ //if insideOutValue=0; we want to retrieve ouside points
+ //if insideOutValue=1; we want to retrieve inside points
+ vtkSmartPointer<vtkPoints> outputPoints = vtkSmartPointer<vtkPoints>::New();
+ vtkSmartPointer<vtkStringArray> outputStrings = vtkSmartPointer<vtkStringArray>::New();
+ outputStrings->SetName("labels");
+ for(vtkIdType i=0;i<input->GetNumberOfPoints();i++) {
+ //
+ double* currentPoint = input->GetPoint(i);
+ double currentIFvalue = currentImpliciteFunction->FunctionValue(currentPoint);
+ //if currentIFvalue>0, current point is outside the clip
+ if (currentIFvalue>0 && insideOutValue==0) {
+ outputPoints->InsertNextPoint(currentPoint);
+ vtkStdString label = inputLabels->GetValue(i);
+ outputStrings->InsertNextValue(label);
+ }
+ //currentIFvalue<=0, current point is inside the clip
+ else if (currentIFvalue<=0 && insideOutValue==1) {
+ outputPoints->InsertNextPoint(currentPoint);
+ vtkStdString label = inputLabels->GetValue(i);
+ outputStrings->InsertNextValue(label);
+ }
+ else {
+ //vtkErrorMacro("vvClipPolyData - NOT IMPLEMENTED");
+ }
+ }
+ //
+ output->ShallowCopy(input);
+ output->SetPoints(outputPoints);
+ output->GetPointData()->AddArray(outputStrings);
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+
+void vvClipPolyData::PrintSelf(ostream& os, vtkIndent indent)
+{
+ this->Superclass::PrintSelf(os,indent);
+}
--- /dev/null
+#ifndef VVCLIPPOLYDATA_H
+#define VVCLIPPOLYDATA_H
+
+#include "vtkClipPolyData.h"
+
+class vvClipPolyData : public vtkClipPolyData
+{
+public:
+ vtkTypeMacro(vvClipPolyData,vtkClipPolyData);
+ void PrintSelf(ostream& os, vtkIndent indent);
+
+ static vvClipPolyData *New();
+
+protected:
+ vvClipPolyData();
+ ~vvClipPolyData();
+
+ int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
+
+private:
+ vvClipPolyData(const vvClipPolyData&); // Not implemented.
+ void operator=(const vvClipPolyData&); // Not implemented.
+};
+
+#endif // VVCLIPPOLYDATA_H
}
mPolyData = vtkPolyData::New();
mIds = vtkFloatArray::New();
+ mLabels = vtkStringArray::New();
+ mLabels->SetName("labels");
}
//--------------------------------------------------------------------
mIds->Delete();
if (mPolyData)
mPolyData->Delete();
+ if (mLabels)
+ mLabels->Delete();
}
//--------------------------------------------------------------------
void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value)
{
vvLandmark point;
+ vtkIdType idPoint;
point.coordinates[0] = x;
point.coordinates[1] = y;
point.coordinates[2] = z;
point.coordinates[3] = t;
point.pixel_value=value;
mLandmarks.push_back(point);
- mPoints[int(t)]->InsertNextPoint(x,y,z);
-
+
+ idPoint = mPoints[int(t)]->InsertNextPoint(x,y,z);
+ std::string str_vtkIdType; // string which will contain the result
+ std::ostringstream convert; // stream used for the conversion
+ convert << idPoint; // insert the textual representation of 'idPoint' in the characters in the stream
+ str_vtkIdType = convert.str(); // set 'str_vtkIdType' to the contents of the stream
+ mLabels->InsertNextValue(str_vtkIdType.c_str());
+
std::stringstream numberVal;
numberVal << (mLandmarks.size()-1);
/*
{
mPoints[mLandmarks.back().coordinates[3]]->SetNumberOfPoints(
mPoints[mLandmarks.back().coordinates[3]]->GetNumberOfPoints()-1);
- mPolyData->Modified();
// mText.pop_back();
mLandmarks.pop_back();
mIds->RemoveLastTuple();
+ mLabels->SetNumberOfValues(mLabels->GetNumberOfValues()-1);
+ mLabels->Modified();
+ mPolyData->Modified();
}
//--------------------------------------------------------------------
// pologyons linking the points
int npoints = mPoints[mLandmarks[index].coordinates[3]]->GetNumberOfPoints();
int t = mLandmarks[index].coordinates[3];
- for (int i = index; i < npoints - 1; i++)
+ for (int i = index; i < npoints - 1; i++) {
mPoints[t]->InsertPoint(i, mPoints[t]->GetPoint(i+1));
+ std::string str_i; // string which will contain the result
+ std::ostringstream convert; // stream used for the conversion
+ convert << i; // insert the textual representation of 'i' in the characters in the stream
+ str_i = convert.str(); // set 'str_i' to the contents of the stream
+ mLabels->SetValue(i,str_i.c_str());
+ }
mPoints[t]->SetNumberOfPoints(npoints-1);
+ mLabels->SetNumberOfValues(npoints-1);
+ mLabels->Modified();
mPolyData->Modified();
mLandmarks.erase(mLandmarks.begin() + index);
}
mFilename = filename;
mLandmarks.clear();
+ vtkIdType idPoint;
char line[255];
for (unsigned int i = 0; i < mPoints.size(); i++)
mPoints[i]->SetNumberOfPoints(0);
// DD(point.comments);
mLandmarks.push_back(point);
mIds->InsertNextTuple1(0.55);
- mPoints[int(point.coordinates[3])]->InsertNextPoint(
+ idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint(
point.coordinates[0],point.coordinates[1],point.coordinates[2]);
+ std::string str_vtkIdType; // string which will contain the result
+ std::ostringstream convert; // stream used for the conversion
+ convert << idPoint; // insert the textual representation of 'idPoint' in the characters in the stream
+ str_vtkIdType = convert.str(); // set 'str_vtkIdType' to the contents of the stream
+ mLabels->InsertNextValue(str_vtkIdType.c_str());
}
}
SetTime(0);
if (time >= 0 && time <= ((int)mPoints.size() -1)) {
mPolyData->SetPoints(mPoints[time]);
mPolyData->GetPointData()->SetScalars(mIds);
+ mPolyData->GetPointData()->AddArray(mLabels);
mPolyData->Modified();
mPolyData->Update();
}
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vvLandmarksGlyph.h"
+#include "vtkStringArray.h"
//typedef
struct vvLandmark {
std::vector<vtkPoints*> mPoints;
vtkFloatArray* mIds;
//std::vector<vvLandmarksGlyph*> mText;
+ vtkStringArray* mLabels;
std::string mFilename;
int mFormatVersion;
};
#define COLUMN_IMAGE_NAME 7
#if CLITK_PRIVATE_FEATURES
- #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.usf)"
+ #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan *.usf)"
#else
- #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr)"
+ #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan)"
#endif
/*Data Tree values
#include <vtkDataArray.h>
#include <vtkFloatArray.h>
#include <vtkClipPolyData.h>
+#include <vtkActor2DCollection.h>
#include <vtkGlyph3D.h>
#include <vtkMath.h>
#include <vtkCursor3D.h>
if (!mCross)
mCross = vtkSmartPointer<vtkCursor3D>::New();
+ if (!mClipBox)
+ mClipBox = vtkSmartPointer<vtkBox>::New();
+ if (!mLandClipper)
+ mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
+ if (!mLandGlyph)
+ mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
+ if (!mLandMapper)
+ mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+ if (!mLandActor)
+ mLandActor = vtkSmartPointer<vtkActor>::New();
+
mCross->SetFocalPoint(0.0,0.0,0.0);
mCross->SetModelBounds(-10,10,-10,10,-10,10);
mCross->AllOff();
mCross->AxesOn();
- if (!mLandGlyph)
- mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
+ mLandClipper->SetClipFunction(mClipBox);
+ mLandClipper->InsideOutOn();
+ mLandClipper->SetInput(mLandmarks->GetOutput());
+
mLandGlyph->SetSource(mCross->GetOutput());
- mLandGlyph->SetInput(landmarks->GetOutput());
+ mLandGlyph->SetInput(mLandClipper->GetOutput());
//mLandGlyph->SetIndexModeToScalar();
- mLandGlyph->SetRange(0,1);
- mLandGlyph->ScalingOff();
-
- mLandGlyph->SetColorModeToColorByScalar();
+ //mLandGlyph->SetRange(0,1);
+ //mLandGlyph->ScalingOff();
- if (!mClipBox)
- mClipBox = vtkSmartPointer<vtkBox>::New();
- if (!mLandClipper)
- mLandClipper = vtkSmartPointer<vtkClipPolyData>::New();
- mLandClipper->InsideOutOn();
- mLandClipper->SetInput(mLandGlyph->GetOutput());
- mLandClipper->SetClipFunction(mClipBox);
+ //mLandGlyph->SetColorModeToColorByScalar();
+
+ mLandGlyph->SetScaleModeToDataScalingOff();
+ mLandGlyph->SetIndexModeToOff();
- if (!mLandMapper)
- mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
- mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
+ mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
//mLandMapper->ScalarVisibilityOff();
- if (!mLandActor)
- mLandActor = vtkSmartPointer<vtkActor>::New();
mLandActor->SetMapper(mLandMapper);
mLandActor->GetProperty()->SetColor(255,10,212);
mLandActor->SetPickable(0);
{
vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
if (pd->GetPoints()) {
- mLandGlyph->SetRange(0,1);
- mLandGlyph->Modified();
- mLandGlyph->Update();
+ //mLandGlyph->SetRange(0,1);
+ //mLandGlyph->Modified();
+ //mLandGlyph->Update();
mClipBox->Modified();
mLandClipper->Update();
mLandMapper->Update();
+ //Let's add the captions
+ //First remove all captions:
+ for(unsigned int i=0;i<mLandLabelActors.size();i++) {
+ this->Renderer->RemoveActor2D(mLandLabelActors[i]);
+ //allActors2D->Remove (mLandLabelActors[i]);
+ }
+ mLandLabelActors.clear();
+ //Next add the captions to the displayed points
+ for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
+ double *position = mLandClipper->GetOutput()->GetPoint(id);
+ vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
+ vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
+ label_actor->SetCaption(label);
+ label_actor->SetAttachmentPoint(position);
+ label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
+ label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
+ label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
+ label_actor->GetCaptionTextProperty()->SetBold(0);
+ label_actor->GetCaptionTextProperty()->SetFontSize(6);
+ label_actor->BorderOff();
+ label_actor->LeaderOff();
+ label_actor->ThreeDimensionalLeaderOff();
+ mLandLabelActors.push_back(label_actor);
+ this->Renderer->AddActor2D(mLandLabelActors[id]);
+ }
}
}
#include "vvImage.h"
#include "vvMesh.h"
#include "vvMeshActor.h"
+#include "vvClipPolyData.h"
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkImageReslice.h>
#include <vtkImageMapToColors.h>
+#include <vtkCaptionActor2D.h>
class vtkActor;
class vtkActor2D;
vtkSmartPointer<vtkActor> mVFActor;
vtkSmartPointer<vtkGlyph3D> mLandGlyph;
vtkSmartPointer<vtkCursor3D> mCross;
- vtkSmartPointer<vtkClipPolyData> mLandClipper;
+ vtkSmartPointer<vvClipPolyData> mLandClipper;
vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
vtkSmartPointer<vtkActor> mLandActor;
+ std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
vtkSmartPointer<vtkBox> mClipBox;
vtkSmartPointer<vtkScalarBarActor> legend;
std::vector<vvMeshActor*> mSurfaceCutActors;