Commit c038db64 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 1db210f6
/*=========================================================================
Program: Visualization Library
Module: DStreamL.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlDashedStreamLine - generate constant-time dashed streamline in arbitrary dataset
// .SECTION Description
// vlStreamLine is a filter that generates a streamline for an arbitrary
// dataset. The streamline consists of a series of dashes, each of which
// represents a constant time increment. (A streamline is a line that is
// everywhere tangent to the vector field (see vlStreamLine).
#ifndef __vlDashedStreamLine_h
#define __vlDashedStreamLine_h
#include "StreamL.hh"
class vlDashedStreamLine : public vlStreamLine
{
public:
vlDashedStreamLine();
~vlDashedStreamLine() {};
char *GetClassName() {return "vlDashedStreamLine";};
void PrintSelf(ostream& os, vlIndent indent);
// Description:
// For each dash, specify the fraction of the dash that is "on". A factor
// of 1.0 will result in a continuous line, a factor of 0.5 will result in
// dashed that are half on and half off.
vlSetClampMacro(DashFactor,float,0.01,1.0);
vlGetMacro(DashFactor,float);
protected:
// Convert streamer array into vlPolyData
void Execute();
// the fraction of on versus off in dash
float DashFactor;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: EdgePts.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlEdgePoints - generate points on iso-surface
// .SECTION Description
// vlEdgePoints is a filter that takes as input any dataset and
// generates on output points that lie on an iso-surface. The points are
// created by interpolation along cells whose end-points are below and
// above the contour value.
// vlEdgePoints can be considered a "poor man's" dividing cubes algorithm.
// Points are generated only on the edges of cells, not in the interior.
#ifndef __vlEdgePoints_h
#define __vlEdgePoints_h
#include "DS2PolyF.hh"
#define MAX_CONTOURS 256
class vlEdgePoints : public vlDataSetToPolyFilter
{
public:
vlEdgePoints();
~vlEdgePoints();
char *GetClassName() {return "vlEdgePoints";};
void PrintSelf(ostream& os, vlIndent indent);
// Description:
// Set/get the contour value.
vlSetMacro(Value,float);
vlGetMacro(Value,float);
protected:
void Execute();
float Value;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: StreamPt.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlStreamPoints - generate points along streamer separated by constant time increment
// .SECTION Description
// vlStreamPoints is a filter that generates points along a streamer.
// The points are separated by a constant time increment. The resulting visual
// effect (especially when coupled with vlGlyph3D) is an indication of particle
// speed.
#ifndef __vlStreamPoints_h
#define __vlStreamPoints_h
#include "Streamer.hh"
class vlStreamPoints : public vlStreamer
{
public:
vlStreamPoints();
~vlStreamPoints() {};
char *GetClassName() {return "vlStreamPoints";};
void PrintSelf(ostream& os, vlIndent indent);
// Description:
// Specify the separation of points in terms of absolute time.
vlSetClampMacro(TimeIncrement,float,0.000001,LARGE_FLOAT);
vlGetMacro(TimeIncrement,float);
protected:
// Convert streamer array into vlPolyData
void Execute();
// the separation of points
float TimeIncrement;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: Streamer.hh
Language: C++
Date: $Date$
Version: $Revision$
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
=========================================================================*/
// .NAME vlStreamer - abstract object implements integration of massless particle through vector field
// .SECTION Description
// vlStreamer is a filter that integrates a massless particle through a vector
// field. The integration is performed using 2cnd order Runge-Kutta method.
// vlStreamer often serves as a base class for other classes that perform
// numerical integration through a vector field (e.g., vlStreamLine).
// Note that vlStreamer can integrate both forward and backward in time, or
// in both directions. The length of the streamer time) is controlled by
// specifying an elapsed time. (The elapsed time is the time each particle
// travels). Otherwise, the integration terminates after exiting the dataset.
// vlStreamer integrates through any type of dataset. Thus if the dataset
// contains 2D cells such as polygons or triangles, the integration is
// constrained to lie on the surface defined by the 2D cells.
// The starting point of streamers may be defined in three different ways.
// Starting from global x-y-z "position" allows you to start a single streamer
// at a specified x-y-z coordinate. Starting from "location" allows you to
// start at a specified cell, subId, and parametric coordinate. Finally, you
// may specify a source object to start multiple streamers. If you start
// streamers using a source object, for each point (that is inside the dataset)
// a streamer is created.
// vlStreamer implements the Execute() method that its superclass vlFilter
// requires. However, its subclasses use this method to generate data, and then
// build their own data.
#ifndef __vlStreamer_h
#define __vlStreamer_h
#include "DS2PolyF.hh"
#define INTEGRATE_FORWARD 0
#define INTEGRATE_BACKWARD 1
#define INTEGRATE_BOTH_DIRECTIONS 2
#define START_FROM_POSITION 0
#define START_FROM_LOCATION 1
typedef struct _vlStreamPoint {
float x[3]; // position
int cellId; // cell
int subId; // cell sub id
float p[3]; // parametric coords in cell
float v[3]; // velocity
float speed; // velocity norm
float s; // scalar value
float t; // time travelled so far
float d; // distance travelled so far
float w[3]; // vorticity (if vorticity is computed)
float n[3]; // normal (if vorticity is computed)
} vlStreamPoint;
//
// Special classes for manipulating data
//
//BTX - begin tcl exclude
//
class vlStreamArray { //;prevent man page generation
public:
vlStreamArray();
~vlStreamArray() {if (this->Array) delete [] this->Array;};
int GetNumberOfPoints() {return this->MaxId + 1;};
vlStreamPoint *GetStreamPoint(int i) {return this->Array + i;};
vlStreamPoint *InsertNextStreamPoint()
{
if ( ++this->MaxId >= this->Size ) this->Resize(this->MaxId);
return this->Array + this->MaxId;
}
vlStreamPoint *Resize(int sz); //reallocates data
void Reset() {this->MaxId = -1;};
vlStreamPoint *Array; // pointer to data
int MaxId; // maximum index inserted thus far
int Size; // allocated size of data
int Extend; // grow array by this amount
float Direction; // integration direction
};
//ETX - end tcl exclude
//
class vlStreamer : public vlDataSetToPolyFilter
{
public:
vlStreamer();
~vlStreamer() {};
char *GetClassName() {return "vlStreamer";};
void PrintSelf(ostream& os, vlIndent indent);
void SetStartLocation(int cellId, int subId, float pcoords[3]);
int GetStartLocation(int& subId, float pcoords[3]);
void SetStartPosition(float x[3]);
float *GetStartPosition();
void Update();
// Description:
// Specify the source object used to generate starting points.
vlSetObjectMacro(Source,vlDataSet);
vlGetObjectMacro(Source,vlDataSet);
// Description:
// Specify the maximum length of the Streamer expressed in elapsed time.
vlSetClampMacro(MaximumPropagationTime,float,0.0,LARGE_FLOAT);
vlGetMacro(MaximumPropagationTime,float);
// Description:
// Specify the direction in which to integrate the Streamer.
vlSetClampMacro(IntegrationDirection,int,
INTEGRATE_FORWARD,INTEGRATE_BOTH_DIRECTIONS);
vlGetMacro(IntegrationDirection,int);
// Description:
// Specify a nominal integration step size (expressed as a fraction of
// the size of each cell).
vlSetClampMacro(IntegrationStepLength,float,0.001,0.5);
vlGetMacro(IntegrationStepLength,float);
// Description:
// Turn on/off the creation of scalar data from velocity magnitude. If off,
// and input dataset has scalars, input dataset scalars are used.
vlSetMacro(SpeedScalars,int);
vlGetMacro(SpeedScalars,int);
vlBooleanMacro(SpeedScalars,int);
// Description:
// Set/get terminal speed (i.e., speed is velocity magnitude). Terminal
// speed is speed at which streamer will terminate propagation.
vlSetClampMacro(TerminalSpeed,float,0.0,LARGE_FLOAT);
vlGetMacro(TerminalSpeed,float);
// Description:
// Turn on/off the computation of vorticity.
vlSetMacro(Vorticity,int);
vlGetMacro(Vorticity,int);
vlBooleanMacro(Vorticity,int);
protected:
// Integrate data
void Integrate();
// Special method for computing streamer vorticity
void ComputeVorticity();
// Controls where streamlines start from (either position or location).
int StartFrom;
// Starting from cell location
int StartCell;
int StartSubId;
float StartPCoords[3];
// starting from global x-y-z position
float StartPosition[3];
//points used to seed streamlines
vlDataSet *Source;
//array of streamers
vlStreamArray *Streamers;
int NumberOfStreamers;
// length of Streamer is generated by time, or by MaximumSteps
float MaximumPropagationTime;
// integration direction
int IntegrationDirection;
// the length (fraction of cell size) of integration steps
float IntegrationStepLength;
// boolean controls whether vorticity is computed
int Vorticity;
// terminal propagation speed
float TerminalSpeed;
// boolean controls whether data scalars or velocity magnitude are used
int SpeedScalars;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: DStreamL.cc
Language: C++
Date: $Date$
Version: $Revision$
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 "DStreamL.hh"
vlDashedStreamLine::vlDashedStreamLine()
{
this->DashFactor = 0.75;
}
void vlDashedStreamLine::Execute()
{
vlStreamPoint *sPrev, *sPtr;
vlFloatPoints *newPts;
vlFloatVectors *newVectors;
vlFloatScalars *newScalars=NULL;
vlCellArray *newLines;
int i, ptId, j, pts[2];
float tOffset, dashOffset, x[3], v[3], s, r;
this->vlStreamer::Integrate();
if ( this->NumberOfStreamers <= 0 ) return;
//
// Convert streamer into lines. Lines may be dashed.
//
newPts = new vlFloatPoints(1000);
newVectors = new vlFloatVectors(1000);
if ( this->Input->GetPointData()->GetScalars() || this->SpeedScalars )
newScalars = new vlFloatScalars(1000);
newLines = new vlCellArray();
newLines->Allocate(newLines->EstimateSize(2*this->NumberOfStreamers,MAX_CELL_SIZE));
//
// Loop over all streamers generating points
//
for (ptId=0; ptId < this->NumberOfStreamers; ptId++)
{
tOffset = 0.0;
if ( this->Streamers[ptId].GetNumberOfPoints() < 2 ) continue;
if ( this->Streamers[ptId].GetNumberOfPoints() == 2 )
{
sPtr=this->Streamers[ptId].GetStreamPoint(1);
if ( sPtr->cellId < 0 ) continue;
}
for ( sPrev=sPtr=this->Streamers[ptId].GetStreamPoint(0), i=0;
i < this->Streamers[ptId].GetNumberOfPoints() && sPtr->cellId >= 0;
i++, sPrev=sPtr, sPtr=this->Streamers[ptId].GetStreamPoint(i) )
{
if ( i == 0 ) //create first point
{
pts[0] = newPts->InsertNextPoint(sPtr->x);
newVectors->InsertVector(pts[0],sPtr->v);
if ( newScalars ) newScalars->InsertScalar(pts[0],sPtr->s);
continue;
}
//
// Start point of dash created here
//
if ( (sPtr->t - tOffset) > this->DashTime )
{
r = (this->DashTime - (sPrev->t-tOffset)) / (sPtr->t - sPrev->t);
for (j=0; j<3; j++)
{
x[j] = sPrev->x[j] + r * (sPtr->x[j] - sPrev->x[j]);
v[j] = sPrev->v[j] + r * (sPtr->v[j] - sPrev->v[j]);
}
pts[0] = newPts->InsertNextPoint(x);
newVectors->InsertVector(pts[0],v);
if ( newScalars )
{
s = sPrev->s + r * (sPtr->s - sPrev->s);
newScalars->InsertScalar(pts[0],s);
}
tOffset += this->DashTime;
}
//
// End point of dash created here
//
dashOffset = this->DashTime * this->DashFactor;
if ( (sPtr->t - dashOffset) > this->DashTime )
{
r = (this->DashTime - (sPrev->t-dashOffset)) / (sPtr->t - sPrev->t);
for (j=0; j<3; j++)
{
x[j] = sPrev->x[j] + r * (sPtr->x[j] - sPrev->x[j]);
v[j] = sPrev->v[j] + r * (sPtr->v[j] - sPrev->v[j]);
}
pts[1] = newPts->InsertNextPoint(x);
newVectors->InsertVector(pts[1],v);
if ( newScalars )
{
s = sPrev->s + r * (sPtr->s - sPrev->s);
newScalars->InsertScalar(pts[1],s);
}
newLines->InsertNextCell(2,pts);
dashOffset += this->DashTime;
}
} //for this streamer
} //for all streamers
//
// Update ourselves
//
vlDebugMacro(<<"Created " << newPts->GetNumberOfPoints() << " points, "
<< newLines->GetNumberOfCells() << " lines");
this->SetPoints(newPts);
this->PointData.SetVectors(newVectors);
if ( newScalars ) this->PointData.SetScalars(newScalars);
this->SetLines(newLines);
this->Squeeze();
}
void vlDashedStreamLine::PrintSelf(ostream& os, vlIndent indent)
{
vlStreamLine::PrintSelf(os,indent);
os << indent << "Dash Factor: " << this->DashFactor << " <<\n";
}
/*=========================================================================
Program: Visualization Library
Module: EdgePts.cc
Language: C++
Date: $Date$
Version: $Revision$
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 "EdgePts.hh"
// Description:
// Construct object with contour value of 0.0.
vlEdgePoints::vlEdgePoints()
{
this->Value = 0.0;
}
vlEdgePoints::~vlEdgePoints()
{
}
//
// General filter: handles arbitrary input.
//
void vlEdgePoints::Execute()
{
vlScalars *inScalars;
vlFloatPoints *newPts;
vlCellArray *newVerts;
vlDebugMacro(<< "Generating edge points");
//
// Initialize and check input
//
this->Initialize();
if ( ! (inScalars = this->Input->GetPointData()->GetScalars()) )
{
vlErrorMacro(<<"No scalar data to contour");
return;
}
range = inScalars->GetRange();
if ( value < range[0] || value > range[1] )
{
vlErrorMacro(<<"Value lies outside of scalar range");
return;
}
//
// Traverse all edges. Since edges are not explicitly represented, use a
// trick: traverse all cells and obtain cell edges and then cell edge
// neighbors. If cell id < all edge neigbors ids, then this edge has not
// yet been visited and is processed.
//
for (cellId=0; cellId<Input->GetNumberOfCells(); cellId++)
{
cell = Input->GetCell(cellId);
cellPts = cell->GetPointIds();
inScalars->GetScalars(*cellPts,cellScalars);
// loop over 8 points of voxel to check if cell straddles value
for ( above=below=0, ptId=0; ptId < cell->GetNumberOfPoints(); ptId++ )
{
if ( cellScalars.GetScalar(ptId) >= this->Value )
above = 1;
else if ( cellScalars.GetScalar(ptId) < this->Value )
below = 1;
}
if ( above && below ) //contour passes through cell
{
if ( cell->GetCellDimension() < 2 ) //only points can be generated
{
cell->Contour(value, &cellScalars, newPts, newVerts, NULL,
NULL, newScalars);
}
else //
{
numEdges = cell->GetNumberOfEdges();
for (edgeId=0; edgeId < numEdges; edgeId++)
{
edge = cell->GetEdge(edgeId);
inScalars->GetScalars(edge->PointIds,cellScalars);
if ( ((s0=cellScalars.GetScalar(0)) < this->Value &&
(s1=cellScalars.GetScalar(1)) >= this->Value) ||
(s0 >= this->Value && s1 < this->Value) )
{
this->GetCellNeighbors(cellId,edge->PointIds,neighbors);
for (i=0; i<neighbors.GetNumberOf
}
}
}
}
vlDebugMacro(<<"Created: " << newPts->GetNumberOfPoints() << " points");
//
// Update ourselves. Because we don't know up front how many verts, lines,
// polys we've created, take care to reclaim memory.
//
this->SetPoints(newPts);
this->SetVerts(newVerts);
this->Squeeze();
}
void vlEdgePoints::PrintSelf(ostream& os, vlIndent indent)
{
vlStructuredPointsToPolyDataFilter::PrintSelf(os,indent);
os << indent << "Contour Values: " << this->Value << "\n";
}