Commit 2939affe authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent a292c3d3
/*=========================================================================
Program: Visualization Library
Module: MergeF.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
=========================================================================*/
//
// Extracts cells where scalar value of every point in cell satisfies
// threshold criterion.
//
#ifndef __vlMergeFilter_h
#define __vlMergeFilter_h
#include "DS2UGrid.hh"
class vlMergeFilter : public vlDataSet, public vlFilter
{
public:
vlMergeFilter();
~vlMergeFilter();
char *GetClassName() {return "vlMergeFilter";};
void PrintSelf(ostream& os, vlIndent indent);
// dataset interface
vlDataSet *MakeObject() {return this->Geometry->MakeObject();};
int GetNumberOfCells() {return this->Geometry->GetNumberOfCells();}
int GetNumberOfPoints() {return this->Geometry->GetNumberOfPoints();}
float *GetPoint(int i) {return this->Geometry->GetPoint(i);}
vlCell *GetCell(int cellId) {return this->Geometry->GetCell(cellId);}
int GetCellType(int cellId) {return this->Geometry->GetCellType(cellId);}
void Initialize();
void GetCellPoints(int cellId, vlIdList *ptIds)
{this->Geometry->GetCellPoints(cellId, ptIds);};
void GetPointCells(int ptId, vlIdList *cellIds)
{this->Geometry->GetPointCells(ptId, cellIds);};
int FindCell(float x[3], vlCell *cell, float tol2)
{return this->Geometry->FindCell(x,cell,tol2);};
void ComputeBounds() {this->Geometry->ComputeBounds();};
vlMapper *MakeMapper();
// Filter interface
void Update();
// Components to merge
vlSetObjectMacro(Geometry,vlDataSet);
vlGetObjectMacro(Geometry,vlDataSet);
vlSetObjectMacro(Scalars,vlDataSet);
vlGetObjectMacro(Scalars,vlDataSet);
vlSetObjectMacro(Vectors,vlDataSet);
vlGetObjectMacro(Vectors,vlDataSet);
vlSetObjectMacro(Normals,vlDataSet);
vlGetObjectMacro(Normals,vlDataSet);
vlSetObjectMacro(TCoords,vlDataSet);
vlGetObjectMacro(TCoords,vlDataSet);
protected:
// Usual data generation method
void Execute();
vlDataSet *Geometry; // output geometry
vlDataSet *Scalars; // scalars to merge
vlDataSet *Vectors; // vectors
vlDataSet *Normals; // normals
vlDataSet *TCoords; // texture coords
};
#endif
/*=========================================================================
Program: Visualization Library
Module: MergeF.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 "MergeF.hh"
#include "PolyData.hh"
vlMergeFilter::vlMergeFilter()
{
// prevents dangling reference to DataSet
this->Geometry = new vlPolyData;
this->Geometry->Register(this);
}
vlMergeFilter::~vlMergeFilter()
{
this->Geometry->UnRegister(this);
if ( this->Scalars ) this->Scalars->UnRegister(this);
if ( this->Vectors ) this->Vectors->UnRegister(this);
if ( this->Normals ) this->Normals->UnRegister(this);
if ( this->TCoords ) this->TCoords->UnRegister(this);
}
void vlMergeFilter::Update()
{
this->Geometry->Update();
if ( this->Scalars ) this->Scalars->Update();
if ( this->Vectors ) this->Vectors->Update();
if ( this->Normals ) this->Normals->Update();
if ( this->TCoords ) this->TCoords->Update();
}
void vlMergeFilter::Initialize()
{
if ( this->Geometry )
{
this->Geometry->UnRegister(this);
// copies input geometry to internal data set
this->Geometry = this->Geometry->MakeObject();
this->Geometry->Register(this);
}
else
{
return;
}
}
vlMapper *vlMergeFilter::MakeMapper()
{
//
// A little tricky because mappers must be of concrete type, but this class
// deals at abstract level of DataSet. Depending upon Input member of this
// filter, mapper may change. Hence need to anticipate change in Input and
// create new mappers as necessary.
//
vlMapper *mapper;
mapper = this->Geometry->MakeMapper();
if ( !this->Mapper || mapper != this->Mapper )
{
if (this->Mapper) this->Mapper->UnRegister(this);
this->Mapper = mapper;
this->Mapper->Register(this);
}
return this->Mapper;
}
void vlMergeFilter::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlMergeFilter::GetClassName()))
{
this->PrintWatchOn(); // watch for multiple inheritance
vlFilter::PrintSelf(os,indent);
vlDataSet::PrintSelf(os,indent);
os << indent << "Geometry: (" << this->Geometry << ")\n";
os << indent << "Geometry type: " << this->Geometry->GetClassName() << "\n";
if ( this->Scalars )
os << indent << "Scalars: (" << this->Scalars << ")\n";
else
os << indent << "Scalars: (none)\n";
if ( this->Vectors )
os << indent << "Vectors: (" << this->Vectors << ")\n";
else
os << indent << "Vectors: (none)\n";
if ( this->Normals )
os << indent << "Normals: (" << this->Normals << ")\n";
else
os << indent << "Normals: (none)\n";
if ( this->TCoords )
os << indent << "TCoords: (" << this->TCoords << ")\n";
else
os << indent << "TCoords: (none)\n";
this->PrintWatchOff(); // stop worrying about it now
}
}
// Merge it all together
void vlMergeFilter::Execute()
{
int numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0;
vlPointData *pd;
vlScalars *scalars;
vlVectors *vectors;
vlNormals *normals;
vlTCoords *tcoords;
vlDebugMacro(<<"Merging data!");
// geometry is created
this->Initialize();
if ( (numPts = this->Geometry->GetNumberOfPoints()) < 1 )
{
vlErrorMacro(<<"Nothing to merge!");
return;
}
if ( this->Scalars )
{
pd = this->Scalars->GetPointData();
scalars = pd->GetScalars();
if ( scalars != NULL ) numScalars= scalars->GetNumberOfScalars();
}
if ( this->Vectors )
{
pd = this->Vectors->GetPointData();
vectors = pd->GetVectors();
if ( vectors != NULL ) numVectors= vectors->GetNumberOfVectors();
}
if ( this->Normals )
{
pd = this->Normals->GetPointData();
normals = pd->GetNormals();
if ( normals != NULL ) numNormals= normals->GetNumberOfNormals();
}
if ( this->TCoords )
{
pd = this->TCoords->GetPointData();
tcoords = pd->GetTCoords();
if ( tcoords != NULL ) numTCoords= tcoords->GetNumberOfTCoords();
}
// merge data only if it is consistent
if ( numPts == numScalars )
this->PointData.SetScalars(scalars);
if ( numPts == numVectors )
this->PointData.SetVectors(vectors);
if ( numPts == numNormals )
this->PointData.SetNormals(normals);
if ( numPts == numTCoords )
this->PointData.SetTCoords(tcoords);
}
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