Commit 618a87c4 authored by Will Schroeder's avatar Will Schroeder
Browse files

*** empty log message ***

parent d49f9f70
......@@ -12,7 +12,7 @@ public:
vlCellArray() : NumberOfCells(0), Location(0) {};
int Initialize(const int sz, const int ext=1000)
{return this->Ia.Initialize(sz,ext);};
vlCellArray (const int sz, const int ext=1000):NumberOfCells(0),Location(0),Ia(sz,ext){};
vlCellArray (const int sz, const int ext=1000):NumberOfCells(0),Location(0),InsertPoint(0),Ia(sz,ext){};
~vlCellArray() {};
int GetNextCell(int& npts, int* &pts)
{
......@@ -36,16 +36,24 @@ public:
for (int i=0; i<npts-1; i++) this->Ia[id-npts+i+1] = pts[i];
NumberOfCells++;
}
void InsertNextCell(int npts)
{
this->InsertPoint = this->Ia.InsertNextValue(npts) + 1;
NumberOfCells++;
}
void InsertCellPoint(int id)
{this->Ia.InsertValue(this->InsertPoint++,id);};
int GetNumberOfCells() {return NumberOfCells;};
void InitTraversal() {this->Location=0;};
void Squeeze() {this->Ia.Squeeze();};
int EstimateSize(int numCells, int maxPtsPerCell)
{return numCells*(1+maxPtsPerCell);};
private:
protected:
int NumberOfCells;
int Location;
vlIntArray Ia;
int InsertPoint;
};
#endif
......@@ -30,7 +30,7 @@ class vlPointData : public vlObject
public:
vlPointData() : Scalars(0), Vectors(0), Normals(0), TCoords(0) {};
void Initialize();
void CopyInitialize(vlPointData* pd, int sze=0, int ext=1000);
void CopyInitialize(vlPointData* pd, int sFlg=1, int vFlg=1, int nFlg=1, int tFlg=1, int sze=0, int ext=1000);
~vlPointData();
char *GetClassName() {return "vlPointData";};
void PrintSelf(ostream& os, vlIndent indent);
......@@ -56,6 +56,10 @@ protected:
vlVectors *Vectors;
vlNormals *Normals;
vlTCoords *TCoords;
int CopyScalars;
int CopyVectors;
int CopyNormals;
int CopyTCoords;
};
#endif
......
......@@ -29,6 +29,10 @@ public:
float DegreesToRadians() {return 0.018977369;};
float Dot(float x[3], float y[3])
{return x[0]*y[0] + x[1]*y[1] + x[2]*y[2];};
void Cross(float x[3], float y[3], float z[3])
{z[0] = x[1]*y[2] - x[2]*y[1];
z[1] = x[2]*y[0] - x[0]*y[2];
z[2] = x[0]*y[1] - x[1]*y[0];};
float Norm(float x[3])
{return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);};
void RandomSeed(long s);
......
......@@ -31,7 +31,7 @@ vlPointSource::vlPointSource(int numPts)
void vlPointSource::Execute()
{
int i;
float radius, theta, phi, x[3];
float radius, theta, phi, x[3], rho;
vlFloatPoints *newPoints;
vlCellArray *newVerts;
vlMath math;
......@@ -40,18 +40,20 @@ void vlPointSource::Execute()
this->Initialize();
newPoints = new vlFloatPoints(this->NumberOfPoints);
newVerts = new vlCellArray(this->NumberOfPoints);
newVerts = new vlCellArray;
newVerts->Initialize(newVerts->EstimateSize(1,this->NumberOfPoints));
newVerts->InsertNextCell(this->NumberOfPoints);
for (i=0; i<this->NumberOfPoints; i++)
{
phi = math.Pi() * math.Random();
radius = this->Radius * sin((double)phi) * math.Random();
rho = this->Radius * math.Random();
radius = rho * sin((double)phi);
theta = 2.0*math.Pi() * math.Random();
x[0] = this->Center[0] + radius * cos((double)theta);
x[1] = this->Center[1] + radius * sin((double)theta);
x[2] = this->Center[2];// + radius * cos((double)phi);
pts[0] = newPoints->InsertNextPoint(x);
newVerts->InsertNextCell(1,pts);
x[2] = this->Center[2] + rho * cos((double)phi);
newVerts->InsertCellPoint(newPoints->InsertNextPoint(x));
}
//
// Update ourselves
......
......@@ -31,6 +31,11 @@ vlPointData::vlPointData (const vlPointData& pd)
this->TCoords = pd.TCoords;
if(this->TCoords) this->TCoords->Register((void *)this);
this->CopyScalars = 1;
this->CopyVectors = 1;
this->CopyNormals = 1;
this->CopyTCoords = 1;
}
vlPointData::~vlPointData()
......@@ -65,6 +70,11 @@ vlPointData& vlPointData::operator=(vlPointData& pd)
this->SetTCoords(t);
}
this->CopyScalars = pd.CopyScalars;
this->CopyVectors = pd.CopyVectors;
this->CopyNormals = pd.CopyNormals;
this->CopyTCoords = pd.CopyTCoords;
return *this;
}
......@@ -73,22 +83,22 @@ vlPointData& vlPointData::operator=(vlPointData& pd)
//
void vlPointData::CopyData(vlPointData* from_pd, int from_id, int to_id)
{
if ( from_pd->Scalars && this->Scalars )
if ( this->CopyScalars && from_pd->Scalars && this->Scalars )
{
this->Scalars->InsertScalar(to_id,from_pd->Scalars->GetScalar(from_id));
}
if ( from_pd->Vectors && this->Vectors )
if ( this->CopyVectors && from_pd->Vectors && this->Vectors )
{
this->Vectors->InsertVector(to_id,from_pd->Vectors->GetVector(from_id));
}
if ( from_pd->Normals && this->Normals )
if ( this->CopyNormals && from_pd->Normals && this->Normals )
{
this->Normals->InsertNormal(to_id,from_pd->Normals->GetNormal(from_id));
}
if ( from_pd->TCoords && this->TCoords )
if ( this->CopyTCoords && from_pd->TCoords && this->TCoords )
{
this->TCoords->InsertTCoord(to_id,from_pd->TCoords->GetTCoord(from_id));
}
......@@ -134,7 +144,7 @@ void vlPointData::Initialize()
// the input PointData to create (i.e., find initial size of) new objects; otherwise
// use the sze variable.
//
void vlPointData::CopyInitialize(vlPointData* pd, int sze, int ext)
void vlPointData::CopyInitialize(vlPointData* pd, int sFlg, int vFlg, int nFlg, int tFlg, int sze, int ext)
{
vlScalars *s, *newScalars;
vlVectors *v, *newVectors;
......@@ -147,28 +157,28 @@ void vlPointData::CopyInitialize(vlPointData* pd, int sze, int ext)
//
if ( !pd ) return;
if ( (s = pd->GetScalars()) )
if ( (this->CopyScalars = sFlg) && (s = pd->GetScalars()) )
{
if ( sze > 0 ) newScalars = s->MakeObject(sze,ext);
else newScalars = s->MakeObject(s->NumberOfScalars());
this->SetScalars(newScalars);
}
if ( (v = pd->GetVectors()) )
if ( (this->CopyVectors = vFlg) && (v = pd->GetVectors()) )
{
if ( sze > 0 ) newVectors = v->MakeObject(sze,ext);
else newVectors = v->MakeObject(v->NumberOfVectors());
this->SetVectors(newVectors);
}
if ( (n = pd->GetNormals()) )
if ( (this->CopyNormals = nFlg) && (n = pd->GetNormals()) )
{
if ( sze > 0 ) newNormals = n->MakeObject(sze,ext);
else newNormals = n->MakeObject(n->NumberOfNormals());
this->SetNormals(newNormals);
}
if ( (t = pd->GetTCoords()) )
if ( (this->CopyTCoords = tFlg) && (t = pd->GetTCoords()) )
{
if ( sze > 0 ) newTCoords = t->MakeObject(sze,t->GetDimension(),ext);
else newTCoords = t->MakeObject(t->NumberOfTCoords(),t->GetDimension());
......@@ -221,5 +231,11 @@ void vlPointData::PrintSelf(ostream& os, vlIndent indent)
{
os << indent << "Texture Coordinates: (none)\n";
}
os << indent << "Copy Scalars: " << (this->CopyScalars ? "On\n" : "Off\n");
os << indent << "Copy Vectors: " << (this->CopyVectors ? "On\n" : "Off\n");
os << indent << "Copy Normals: " << (this->CopyNormals ? "On\n" : "Off\n");
os << indent << "Copy Texture Coordinates: " << (this->CopyTCoords ? "On\n" : "Off\n");
}
}
......@@ -17,6 +17,9 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "vlMath.hh"
#include "RibbonF.hh"
#include "FPoints.hh"
#include "FNormals.hh"
#include "Line.hh"
vlRibbonFilter::vlRibbonFilter()
{
......@@ -27,17 +30,20 @@ vlRibbonFilter::vlRibbonFilter()
void vlRibbonFilter::Execute()
{
int i, j, k;
float center[3], *p;
vlPoints *inPts;
vlNormals *inNormals;
vlPointData *pd;
vlCellArray *inVerts,*inLines,*inPolys,*inStrips;
int numNewPts, numNewLines, numNewPolys, poly_alloc_size;
vlCellArray *inLines;
int numNewPts;
vlFloatPoints *newPts;
vlFloatNormals *newNormals;
vlCellArray *newStrips;
int npts, *pts;
vlFloatPoints *newPoints;
vlNormals *inNormals;
vlCellArray *newVerts, *newLines, *newPolys;
int newIds[MAX_CELL_SIZE];
float *p1, *p2, *p3, pt[3];
float *x1, *x2, norm, *n, normal[3];
float l[3], pt[3], p[3];
vlMath math;
float theta;
int deleteNormals=0;
//
// Initialize
//
......@@ -45,21 +51,86 @@ void vlRibbonFilter::Execute()
inPts = this->Input->GetPoints();
pd = this->Input->GetPointData();
// copy scalars, vectors, tcoords. Normals are computed here.
this->PointData.CopyInitialize(pd,1,1,0,1);
if ( !(inLines = this->Input->GetLines()) || inLines->GetNumberOfCells() < 1 )
if ( !(inLines = this->Input->GetLines()) ||
inLines->GetNumberOfCells() < 1 )
{
cerr << this->GetClassName() << ": No input data!\n";
return;
}
if (pd)
if ( !(inNormals=pd->GetNormals()) )
{
deleteNormals = 1;
vlLine lineNormalGenerator;
inNormals = new vlFloatNormals(inPts->NumberOfPoints());
if ( !lineNormalGenerator.GenerateNormals(inPts,inLines,(vlFloatNormals*)inNormals) )
{
cerr << this->GetClassName() << ": No normals for line!\n";
delete inNormals;
return;
}
}
numNewPts = inPts->NumberOfPoints() * 2;
newPts = new vlFloatPoints(numNewPts);
newNormals = new vlFloatNormals(numNewPts);
newStrips = new vlCellArray;
newStrips->Initialize(newStrips->EstimateSize(1,numNewPts));
//
// Create pairs of points along the line that are later connected into a
// triangle strip.
//
theta = this->Angle * math.DegreesToRadians();
for (inLines->InitTraversal(); inLines->GetNextCell(npts,pts); )
{
inNormals = pd->GetNormals();
for (j=0; j<npts; j++)
{
// compute first point
x1 = inPts->GetPoint(pts[j]);
n = inNormals->GetNormal(pts[j]);
for (k=0; k<3; k++) pt[k] = x1[k] + this->Radius*n[k];
newPts->InsertNextPoint(pt);
newNormals->InsertNextNormal(n);
// now next point
if ( j < (npts - 1) )
{
x2 = inPts->GetPoint(pts[j+1]);
for (k=0; k<3; k++) l[k] = x2[k] - x1[k];
}
else
{
; // use old l[k]
}
math.Cross(n,l,p);
if ((norm=math.Norm(p)) == 0.0) norm = 1.0;
for (k=0; k<3; k++) p[k] /= norm;
for (k=0; k<3; k++) normal[k] = n[k]*cos((double)theta) + p[k]*sin((double)theta);
for (k=0; k<3; k++) pt[k] = x1[k] + this->Radius*normal[k];
newPts->InsertNextPoint(pt);
newNormals->InsertNextNormal(normal);
}
}
else
//
// Generate the strip topology
//
newStrips->InsertNextCell(numNewPts);
for (i=0; i < numNewPts; i++)
{
; //for now
newStrips->InsertCellPoint(i);
}
//
// Update ourselves
//
if ( deleteNormals ) delete inNormals;
this->SetPoints(newPts);
this->SetStrips(newStrips);
this->PointData.SetNormals(newNormals);
}
void vlRibbonFilter::PrintSelf(ostream& os, vlIndent indent)
......
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