Commit 5f85d2df authored by Charles Law's avatar Charles Law
Browse files

Image to color scalars, forgot a FIleName

parent aab715d1
......@@ -41,6 +41,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include <math.h>
#include "vtkImageToStructuredPoints.h"
#include "vtkBitmap.h"
......@@ -52,6 +53,7 @@ vtkImageToStructuredPoints::vtkImageToStructuredPoints()
this->ScalarInput = NULL;
this->VectorInput = NULL;
this->WholeImage = 1;
this->ColorScalars = 0;
this->InputMemoryLimit = 500000; // A very big image indeed (in kB).
this->SetSplitOrder(VTK_IMAGE_TIME_AXIS, VTK_IMAGE_Z_AXIS,
VTK_IMAGE_Y_AXIS, VTK_IMAGE_X_AXIS);
......@@ -400,6 +402,7 @@ vtkScalars *vtkImageToStructuredPoints::ScalarExecute(vtkImageRegion *region)
// If data is not the same size as the region, we need to reformat.
// Assume that relativeCoordinates == absoluteCoordinates.
// (Copy also required if we have to produce colored scalars.)
dataExtent = region->GetData()->GetExtent();
regionExtent = region->GetExtent();
if (dataExtent[0] != regionExtent[0] || dataExtent[1] != regionExtent[1] ||
......@@ -414,8 +417,16 @@ vtkScalars *vtkImageToStructuredPoints::ScalarExecute(vtkImageRegion *region)
temp->Delete();
}
scalars = region->GetData()->GetPointData()->GetScalars();
scalars->Register(this);
if (this->ColorScalars)
{
scalars = this->CopyToColorScalars(region);
}
else
{
scalars = region->GetData()->GetPointData()->GetScalars();
scalars->Register(this);
}
region->ReleaseData();
return scalars;
}
......@@ -535,6 +546,54 @@ int vtkImageToStructuredPoints::ScalarSplitExecute(vtkImageRegion *outRegion,
}
//----------------------------------------------------------------------------
// The user wants color scalars. Copy image region to color scalars.
// We only handle gray maps for now. Not templated yet either.
vtkScalars *
vtkImageToStructuredPoints::CopyToColorScalars(vtkImageRegion *region)
{
int min0, max0, min1, max1, min2, max2;
vtkGraymap *scalars;
unsigned char *ptr0, *ptr1, *ptr2;
int inc0, inc1, inc2;
int idx0, idx1, idx2;
if (region->GetScalarType() != VTK_UNSIGNED_CHAR)
{
vtkErrorMacro("CopyToColorScalars: Input must be unsigned char");
return NULL;
}
region->GetExtent(min0, max0, min1, max1, min2, max2);
region->GetIncrements(inc0, inc1, inc2);
scalars = new vtkGraymap;
scalars->Allocate((max0-min0+1)*(max1-min1+1)*(max2-min2+1));
ptr2 = (unsigned char *)(region->GetScalarPointer());
for (idx2 = min2; idx2 <= max2; ++idx2)
{
ptr1 = ptr2;
for (idx1 = min1; idx1 <= max1; ++idx1)
{
ptr0 = ptr1;
for (idx0 = min0; idx0 <= max0; ++idx0)
{
scalars->InsertNextGrayValue(*ptr0);
ptr0 += inc0;
}
ptr1 += inc1;
}
ptr2 += inc2;
}
return scalars;
}
//============================================================================
// Vector stuff
//============================================================================
......
......@@ -66,16 +66,25 @@ public:
// Set/Get the scalar input object from the image pipeline.
vtkSetObjectMacro(ScalarInput,vtkImageSource);
vtkGetObjectMacro(ScalarInput,vtkImageSource);
// Description:
// Set/Get the vector input object from the image pipeline.
vtkSetObjectMacro(VectorInput,vtkImageSource);
vtkGetObjectMacro(VectorInput,vtkImageSource);
// Description:
// Set/Get the flag that tells the object to convert the whole image or not.
vtkSetMacro(WholeImage,int);
vtkGetMacro(WholeImage,int);
vtkBooleanMacro(WholeImage,int);
// Description:
// ColorScalarsOn tells this output to create color scalars.
// This object then can be used as input to vtkTIFFWriter.
vtkSetMacro(ColorScalars,int);
vtkGetMacro(ColorScalars,int);
vtkBooleanMacro(ColorScalars,int);
// Set/Get the extent to translate explicitely.
void SetExtent(int dim, int *extent);
vtkImageSetExtentMacro(Extent);
......@@ -116,6 +125,7 @@ protected:
vtkImageSource *ScalarInput;
vtkImageSource *VectorInput;
int WholeImage;
int ColorScalars;
int Coordinate3;
int Extent[VTK_IMAGE_EXTENT_DIMENSIONS];
int Axes[VTK_IMAGE_DIMENSIONS];
......@@ -127,6 +137,7 @@ protected:
vtkScalars *ScalarExecute(vtkImageRegion *region);
int ScalarSplitExecute(vtkImageRegion *outRegion, long volumeLimit);
vtkVectors *VectorExecute(vtkImageRegion *region);
vtkScalars *CopyToColorScalars(vtkImageRegion *region);
};
#endif
......
......@@ -93,6 +93,7 @@ public:
virtual void SetDisplayId(void *) {};
virtual void SetWindowId(void *) {};
virtual void SetParentId(void *) {};
// Description:
// Performed at the end of the rendering process to generate image.
......
......@@ -43,13 +43,13 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
vtkTIFFWriter::vtkTIFFWriter()
{
this->Filename = NULL;
this->FileName = NULL;
this->Orientation = 1;
}
vtkTIFFWriter::~vtkTIFFWriter()
{
if ( this->Filename ) delete [] this->Filename;
if ( this->FileName ) delete [] this->FileName;
}
// Description:
......@@ -98,16 +98,16 @@ void vtkTIFFWriter::WriteData()
bpp = newScalars->GetNumberOfValuesPerScalar();
if ( this->Filename == NULL)
if ( this->FileName == NULL)
{
vtkErrorMacro(<< "Please specify filename to write");
vtkErrorMacro(<< "Please specify FileName to write");
return;
}
fp = fopen(this->Filename,"wb");
fp = fopen(this->FileName,"wb");
if (!fp)
{
vtkErrorMacro(<< "Couldn't open file: " << this->Filename << endl);
vtkErrorMacro(<< "Couldn't open file: " << this->FileName << endl);
return;
}
......@@ -140,8 +140,8 @@ void vtkTIFFWriter::PrintSelf(ostream& os, vtkIndent indent)
{
vtkWriter::PrintSelf(os,indent);
os << indent << "Filename: "
<< (this->Filename ? this->Filename : "(none)") << "\n";
os << indent << "FileName: "
<< (this->FileName ? this->FileName : "(none)") << "\n";
os << indent << "Orientation: "
<< this->Orientation << "\n";
}
......
......@@ -65,8 +65,10 @@ public:
// Description:
// Specify name of file to write.
vtkSetStringMacro(Filename);
vtkGetStringMacro(Filename);
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
void SetFilename(char *str){this->SetFileName(str);}
char *GetFilename(){return this->GetFileName();}
// Description:
// Specify Orientation of image. Default is 1.
......@@ -83,7 +85,7 @@ public:
protected:
void WriteData();
char *Filename;
char *FileName;
int Orientation;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment