Commit 0bf05725 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 1a742ebc
/*=========================================================================
Program: Visualization Library
Module: SPt2SPtF.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// StructuredPointsToStructuredPointsFilter are filters that take
// StructuredPoints as input and generate StructuredPoints data as output
//
#ifndef __vlStructuredPointsToStructuredPointsFilter_h
#define __vlStructuredPointsToStructuredPointsFilter_h
#include "StrPtsF.hh"
#include "StrPts.hh"
class vlStructuredPointsToStructuredPointsFilter : public vlStructuredPoints,
public vlStructuredPointsFilter
{
public:
void Update();
char *GetClassName() {return "vlDataSetToStructuredPointsFilter";};
void PrintSelf(ostream& os, vlIndent indent);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: StrPtsF.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// StructuredPointsFilter takes StructuredPoints as input
//
#ifndef __vlStructuredPointsFilter_h
#define __vlStructuredPointsFilter_h
#include "Filter.hh"
#include "StrPts.hh"
class vlStructuredPointsFilter : public vlFilter
{
public:
vlStructuredPointsFilter();
~vlStructuredPointsFilter();
char *GetClassName() {return "vlStructuredPointsFilter";};
void PrintSelf(ostream& os, vlIndent indent);
void Update();
vlSetObjectMacro(Input,vlStructuredPoints);
vlGetObjectMacro(Input,vlStructuredPoints);
protected:
vlStructuredPoints *Input;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: TranSPts.hh
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Transform (and resample) StructuredPoints using transform object.
//
#ifndef __vlTransformStructuredPoints_h
#define __vlTransformStructuredPoints_h
#include "SPt2SPtF.hh"
#include "Trans.hh"
class vlTransformStructuredPoints : public vlStructuredPointsToStructuredPointsFilter
{
public:
vlTransformStructuredPoints();
~vlTransformStructuredPoints() {};
char *GetClassName() {return "vlTransformStructuredPoints";};
void PrintSelf(ostream& os, vlIndent indent);
vlSetVector3Macro(SampleDimensions,int);
vlGetVectorMacro(SampleDimensions,int);
vlSetMacro(FillValue,float);
vlGetMacro(FillValue,float);
void SetModelBounds(float *bounds);
void SetModelBounds(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax);
vlGetVectorMacro(ModelBounds,float);
vlSetObjectMacro(Transform,vlTransform);
vlGetObjectMacro(Transform,vlTransform);
unsigned long int GetMTime();
protected:
void Execute();
int SampleDimensions[3];
float FillValue;
float ModelBounds[6];
vlTransform *Transform;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: SPt2SPtF.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "SPt2SPtF.hh"
void vlStructuredPointsToStructuredPointsFilter::Update()
{
vlStructuredPointsFilter::Update();
}
void vlStructuredPointsToStructuredPointsFilter::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlStructuredPointsToStructuredPointsFilter::GetClassName()))
{
this->PrintWatchOn(); // watch for multiple inheritance
vlStructuredPoints::PrintSelf(os,indent);
vlStructuredPointsFilter::PrintSelf(os,indent);
this->PrintWatchOff(); // stop worrying about it now
}
}
/*=========================================================================
Program: Visualization Library
Module: StrPtsF.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "StrPtsF.hh"
vlStructuredPointsFilter::vlStructuredPointsFilter()
{
this->Input = NULL;
}
vlStructuredPointsFilter::~vlStructuredPointsFilter()
{
if ( this->Input != NULL )
{
this->Input->UnRegister(this);
}
}
void vlStructuredPointsFilter::Update()
{
// make sure input is available
if ( !this->Input )
{
vlErrorMacro(<< "No input!\n");
return;
}
// prevent chasing our tail
if (this->Updating) return;
this->Updating = 1;
this->Input->Update();
this->Updating = 0;
if (this->Input->GetMTime() > this->GetMTime() || this->GetMTime() > this->ExecuteTime )
{
if ( this->StartMethod ) (*this->StartMethod)();
this->Execute();
this->ExecuteTime.Modified();
if ( this->EndMethod ) (*this->EndMethod)();
}
}
void vlStructuredPointsFilter::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlStructuredPointsFilter::GetClassName()))
{
vlFilter::PrintSelf(os,indent);
if ( this->Input )
{
os << indent << "Input: (" << this->Input << ")\n";
}
else
{
os << indent << "Input: (none)\n";
}
}
}
/*=========================================================================
Program: Visualization Library
Module: TranSPts.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "TranSPts.hh"
vlTransformStructuredPoints::vlTransformStructuredPoints()
{
this->ModelBounds[0] = 0.0;
this->ModelBounds[1] = 0.0;
this->ModelBounds[2] = 0.0;
this->ModelBounds[3] = 0.0;
this->ModelBounds[4] = 0.0;
this->ModelBounds[5] = 0.0;
this->SampleDimensions[0] = 0; // use input dimensions by default
this->SampleDimensions[1] = 0;
this->SampleDimensions[2] = 0;
this->FillValue = LARGE_FLOAT;
this->Transform = NULL;
}
void vlTransformStructuredPoints::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlTransformStructuredPoints::GetClassName()))
{
vlStructuredPointsToStructuredPointsFilter::PrintSelf(os,indent);
os << indent << "Sample Dimensions: (" << this->SampleDimensions[0] << ", "
<< this->SampleDimensions[1] << ", "
<< this->SampleDimensions[2] << ")\n";
os << indent << "ModelBounds: \n";
os << indent << " Xmin,Xmax: (" << this->ModelBounds[0] << ", " << this->ModelBounds[1] << ")\n";
os << indent << " Ymin,Ymax: (" << this->ModelBounds[2] << ", " << this->ModelBounds[3] << ")\n";
os << indent << " Zmin,Zmax: (" << this->ModelBounds[4] << ", " << this->ModelBounds[5] << ")\n";
os << indent << "Fill Value:" << this->FillValue << "\n";
os << indent << "Transform:" << this->Transform << "\n";
}
}
void vlTransformStructuredPoints::SetModelBounds(float *bounds)
{
vlTransformStructuredPoints::SetModelBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
}
void vlTransformStructuredPoints::SetModelBounds(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
{
if (this->ModelBounds[0] != xmin || this->ModelBounds[1] != xmax ||
this->ModelBounds[2] != ymin || this->ModelBounds[3] != ymax ||
this->ModelBounds[4] != zmin || this->ModelBounds[5] != zmax )
{
float length;
this->Modified();
this->ModelBounds[0] = xmin;
this->ModelBounds[1] = xmax;
this->ModelBounds[2] = ymin;
this->ModelBounds[3] = ymax;
this->ModelBounds[4] = zmin;
this->ModelBounds[5] = zmax;
this->Origin[0] = xmin;
this->Origin[1] = ymin;
this->Origin[2] = zmin;
if ( (length = xmax - xmin) == 0.0 ) length = 1.0;
this->AspectRatio[0] = 1.0;
this->AspectRatio[1] = (ymax - ymin) / length;
this->AspectRatio[2] = (zmax - zmin) / length;
}
}
void vlTransformStructuredPoints::Execute()
{
int i, numPts, numOutPts;
int *dimIn;
float *originIn, *aspectIn;
vlPointData *pd;
vlScalars *inScalars, *outScalars;
vlDebugMacro(<<"Transforming points");
this->Initialize();
// make sure there is input
pd = this->Input->GetPointData();
inScalars = pd->GetScalars();
if ( (numPts=this->Input->GetNumberOfPoints()) < 1 ||
inScalars == NULL )
{
vlErrorMacro(<<"No data to transform!");
return;
}
// Get origin, aspect ratio and dimensions from input
dimIn = this->Input->GetDimensions();
originIn = this->Input->GetOrigin();
aspectIn = this->Input->GetAspectRatio();
// if dimensions are not specified, use input's dimensions
if (this->SampleDimensions[0] <= 1 || this->SampleDimensions[1] <= 1 ||
this->SampleDimensions[2] <= 1)
{
for (i = 0; i < 3; i++) this->Dimensions[i] = dimIn[i];
}
// otherwise use the specified dimensions
else
{
for (i = 0; i < 3; i++) this->Dimensions[i] = this->SampleDimensions[i];
}
// if bounds are not specified, use input's aspect ratio and origin
if (this->ModelBounds[0] >= this->ModelBounds[1] ||
this->ModelBounds[2] >= this->ModelBounds[3] ||
this->ModelBounds[4] >= this->ModelBounds[5])
{
for (i = 0; i < 3; i++)
{
this->AspectRatio[i] = aspectIn[i];
this->Origin[i] = originIn[i];
}
}
// otherwise, calculate them from bounds
else
{
for (i = 0; i < 3; i++)
{
this->Origin[i] = this->ModelBounds[2*i];
this->AspectRatio[i] = (this->ModelBounds[2*i+1]-this->ModelBounds[2*i])/
(this->Dimensions[i] - 1);
}
}
// Allocate data. Scalar type is same as input.
numOutPts = this->Dimensions[0] * this->Dimensions[1] * this->Dimensions[2];
outScalars = inScalars->MakeObject(numOutPts);
for (i = 0; i < numOutPts; i++) outScalars->SetScalar(i,this->FillValue);
// Loop over all output voxels, transforming and then resampling from input.
// Need to get inverse transformation matrix to perform transformation.
// Update ourselves
this->PointData.SetScalars(outScalars);
}
unsigned long int vlTransformStructuredPoints::GetMTime()
{
unsigned long int mtime = 0;
if ( this->Transform ) mtime = this->Transform->GetMTime();
return ( mtime > this->MTime ? mtime : this->MTime );
}
Supports Markdown
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