Commit 85ae15ad authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 829eb3e3
/*=========================================================================
Program: Visualization Library
Module: AppendP.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
=========================================================================*/
//
// Appends one or more PolyData datasets together into a single
// PolyData dataset
//
#ifndef __vlAppendPolyData_h
#define __vlAppendPolyData_h
#include "PolyData.hh"
#include "Filter.hh"
#include "PolyDatC.hh"
class vlAppendPolyData : public vlPolyData, public vlFilter
{
public:
vlAppendPolyData();
~vlAppendPolyData();
char *GetClassName() {return "vlAppendPolyData";};
void PrintSelf(ostream& os, vlIndent indent);
void AddInput(vlPolyData *);
void RemoveInput(vlPolyData *);
vlPolyDataCollection *GetInput() {return &(this->Input);};
// filter interface
void Update();
protected:
// Usual data generation method
void Execute();
// list of data sets to append together
vlPolyDataCollection Input;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: PolyDatC.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
=========================================================================*/
#ifndef __vlPolyDataCollection_hh
#define __vlPolyDataCollection_hh
#include "Object.hh"
#include "PolyData.hh"
class vlPolyDataCollectionElement
{
public:
vlPolyData *Item;
vlPolyDataCollectionElement *Next;
};
class vlPolyDataCollection : public vlObject
{
public:
int NumberOfItems;
private:
vlPolyDataCollectionElement *Top;
vlPolyDataCollectionElement *Bottom;
public:
vlPolyDataCollection();
void AddItem(vlPolyData *);
void RemoveItem(vlPolyData *);
int IsItemPresent(vlPolyData *);
int GetNumberOfItems();
vlPolyData *GetItem(int num);
void PrintSelf(ostream& os, vlIndent indent);
char *GetClassName() {return "vlPolyDataCollection";};
};
#endif
/*=========================================================================
Program: Visualization Library
Module: TubeF.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
=========================================================================*/
//
// Generates a tube from input lines. If scalar data is present, will vary
// radius of tube (if turned on).
//
#ifndef __vlTubeFilter_h
#define __vlTubeFilter_h
#include "P2PF.hh"
class vlTubeFilter : public vlPolyToPolyFilter
{
public:
vlTubeFilter();
~vlTubeFilter() {};
char *GetClassName() {return "vlTubeFilter";};
void PrintSelf(ostream& os, vlIndent indent);
vlSetClampMacro(Radius,float,0.0,LARGE_FLOAT);
vlGetMacro(Radius,float);
vlSetMacro(VaryRadius,int);
vlGetMacro(VaryRadius,int);
vlBooleanMacro(VaryRadius,int);
vlSetClampMacro(NumberOfSides,int,0,LARGE_INTEGER);
vlGetMacro(NumberOfSides,int);
vlSetMacro(Rotation,float);
vlGetMacro(Rotation,float);
protected:
// Usual data generation method
void Execute();
float Radius; //minimum radius of tube
int VaryRadius; //controls whether radius varies with scalar data
int NumberOfSides; //number of sides to create tube
float Rotation; //rotation of initial side of tube
};
#endif
/*=========================================================================
Program: Visualization Library
Module: AppendP.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 "AppendP.hh"
vlAppendPolyData::vlAppendPolyData()
{
}
vlAppendPolyData::~vlAppendPolyData()
{
vlDataSet *ds;
for ( int i=0; i < this->Input.GetNumberOfItems(); i++ )
{
ds = this->Input.GetItem(i+1);
ds->UnRegister(this);
}
}
void vlAppendPolyData::AddInput(vlPolyData *ds)
{
if ( ! this->Input.IsItemPresent(ds) )
{
this->Modified();
ds->Register(this);
this->Input.AddItem(ds);
}
}
void vlAppendPolyData::RemoveInput(vlPolyData *ds)
{
if ( this->Input.IsItemPresent(ds) )
{
this->Modified();
ds->UnRegister(this);
this->Input.RemoveItem(ds);
}
}
void vlAppendPolyData::Update()
{
unsigned long int mtime, ds_mtime;
int i;
vlPolyData *ds;
// make sure input is available
if ( this->Input.GetNumberOfItems() < 1 )
{
vlErrorMacro(<< "No input!\n");
return;
}
// prevent chasing our tail
if (this->Updating) return;
this->Updating = 1;
for (mtime=0, i=0; i < this->Input.GetNumberOfItems(); i++)
{
ds = this->Input.GetItem(i+1);
ds_mtime = ds->GetMTime();
if ( ds_mtime > mtime ) mtime = ds_mtime;
ds->Update();
}
this->Updating = 0;
if (mtime > this->GetMTime() || this->GetMTime() > this->ExecuteTime )
{
if ( this->StartMethod ) (*this->StartMethod)();
this->Execute();
this->ExecuteTime.Modified();
if ( this->EndMethod ) (*this->EndMethod)();
}
}
// Append data sets into single unstructured grid
void vlAppendPolyData::Execute()
{
int scalarsPresent, vectorsPresent, normalsPresent, tcoordsPresent;
vlPolyData *ds;
vlPoints *inPts;
vlFloatPoints *newPts;
vlCellArray *inVerts, *newVerts;
vlCellArray *inLines, *newLines;
vlCellArray *inPolys, *newPolys;
vlCellArray *inStrips, *newStrips;
int i, j, ptId, ptOffset;
int numPts, numCells;
vlPointData *pd;
int npts, *pts, newPtIds[MAX_CELL_SIZE];
vlDebugMacro(<<"Appending data together");
this->Initialize();
// loop over all data sets, checking to see what point data is available.
numPts = 0;
numCells = 0;
scalarsPresent = 1;
vectorsPresent = 1;
normalsPresent = 1;
tcoordsPresent = 1;
for ( i=0; i < this->Input.GetNumberOfItems(); i++)
{
ds = this->Input.GetItem(i+1);
numPts += ds->GetNumberOfPoints();
numCells += ds->GetNumberOfCells();
pd = ds->GetPointData();
if ( pd->GetScalars() == NULL ) scalarsPresent &= 0;
if ( pd->GetVectors() == NULL ) vectorsPresent &= 0;
if ( pd->GetNormals() == NULL ) normalsPresent &= 0;
if ( pd->GetTCoords() == NULL ) tcoordsPresent &= 0;
}
if ( numPts < 1 || numCells < 1 )
{
vlErrorMacro(<<"No data to append!");
return;
}
// Now can allocate memory
if ( !scalarsPresent ) this->PointData.CopyScalarsOff();
if ( !vectorsPresent ) this->PointData.CopyVectorsOff();
if ( !normalsPresent ) this->PointData.CopyNormalsOff();
if ( !tcoordsPresent ) this->PointData.CopyTCoordsOff();
this->PointData.CopyAllocate(pd,numPts);
newPts = new vlFloatPoints(numPts);
newVerts = new vlCellArray;
newVerts->Allocate(numCells*4);
newLines = new vlCellArray;
newLines->Allocate(numCells*4);
newPolys = new vlCellArray;
newPolys->Allocate(numCells*4);
newStrips = new vlCellArray;
newStrips->Allocate(numCells*4);
// loop over all input sets
for ( ptOffset=0, i=0; i < this->Input.GetNumberOfItems(); i++, ptOffset+=numPts)
{
ds = this->Input.GetItem(i+1);
pd = ds->GetPointData();
numPts = ds->GetNumberOfPoints();
inPts = ds->GetPoints();
inVerts = ds->GetVerts();
inLines = ds->GetLines();
inPolys = ds->GetPolys();
inStrips = ds->GetStrips();
// copy points and point data
for (ptId=0; ptId < numPts; ptId++)
{
newPts->SetPoint(ptId+ptOffset,inPts->GetPoint(ptId));
this->PointData.CopyData(pd,ptId,ptId+ptOffset);
}
for (inVerts->InitTraversal(); inVerts->GetNextCell(npts,pts); )
{
for (j=0; j < npts; j++) newPtIds[j] = pts[j] + ptOffset;
newVerts->InsertNextCell(npts,newPtIds);
}
for (inLines->InitTraversal(); inLines->GetNextCell(npts,pts); )
{
for (j=0; j < npts; j++) newPtIds[j] = pts[j] + ptOffset;
newLines->InsertNextCell(npts,newPtIds);
}
for (inPolys->InitTraversal(); inPolys->GetNextCell(npts,pts); )
{
for (j=0; j < npts; j++) newPtIds[j] = pts[j] + ptOffset;
newPolys->InsertNextCell(npts,newPtIds);
}
for (inStrips->InitTraversal(); inStrips->GetNextCell(npts,pts); )
{
for (j=0; j < npts; j++) newPtIds[j] = pts[j] + ptOffset;
newStrips->InsertNextCell(npts,newPtIds);
}
}
//
// Update ourselves
//
newVerts->Squeeze();
newLines->Squeeze();
newPolys->Squeeze();
newStrips->Squeeze();
this->SetPoints(newPts);
this->SetVerts(newVerts);
this->SetLines(newLines);
this->SetPolys(newPolys);
this->SetStrips(newStrips);
}
void vlAppendPolyData::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlAppendPolyData::GetClassName()))
{
this->PrintWatchOn(); // watch for multiple inheritance
vlPolyData::PrintSelf(os,indent);
vlFilter::PrintSelf(os,indent);
os << indent << "Input DataSets:\n";
this->Input.PrintSelf(os,indent.GetNextIndent());
this->PrintWatchOff(); // stop worrying about it now
}
}
/*=========================================================================
Program: Visualization Library
Module: TubeF.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 "TubeF.hh"
#include "AppendP.hh"
#include "RibbonF.hh"
vlTubeFilter::vlTubeFilter()
{
this->Radius = 0.5;
this->VaryRadius = 1;
this->NumberOfSides = 3;
this->Rotation = 0.0;
}
void vlTubeFilter::Execute()
{
int i;
int numSides;
vlRibbonFilter **ribbons;
vlAppendPolyData *appendF;
vlPoints *inPoints;
vlCellArray *inLines;
vlPointData *pd;
vlDebugMacro(<<"Creating tube");
this->Initialize();
inPoints = this->Input->GetPoints();
inLines = this->Input->GetLines();
pd = this->Input->GetPointData();
ribbons = new vlRibbonFilter * [numSides];
if ( (numSides=this->GetNumberOfSides()) == 0 ) //just copy lines through
{
this->PointData = *pd;
this->SetPoints(inPoints);
this->SetLines(inLines);
}
else if ( numSides < 3 ) //create ribbons along line
{
appendF = new vlAppendPolyData;
for (i=0; i < numSides; i++)
{
ribbons[i] = new vlRibbonFilter();
ribbons[i]->SetInput(this->Input);
ribbons[i]->SetRadius(0.0);
ribbons[i]->SetAngle(i*90.0);
appendF->AddInput(ribbons[i]);
}
}
else //create offset ribbons that form a tube
{
for (i=0; i < numSides; i++)
{
ribbons[i] = new vlRibbonFilter();
ribbons[i]->SetInput(this->Input);
ribbons[i]->SetRadius(this->Radius);
ribbons[i]->SetAngle(this->Rotation + i*(360.0/numSides));
appendF->AddInput(ribbons[i]);
}
}
appendF->Update(); //cause all ribbons to generate
this->PointData = *(appendF->GetPointData());
this->SetPoints(appendF->GetPoints());
this->SetStrips(appendF->GetStrips());
delete appendF; //side effect deletes all ribbon filters
delete [] ribbons;
}
void vlTubeFilter::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlTubeFilter::GetClassName()))
{
vlPolyToPolyFilter::PrintSelf(os,indent);
os << indent << "Radius: " << this->Radius << "\n";
os << indent << "Vary Radius: " << (this->VaryRadius ? "On\n" : "Off\n");
os << indent << "Number Of Sides: " << this->NumberOfSides << "\n";
os << indent << "Rotation: " << this->Rotation << "\n";
}
}
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