FeatEdge.cc 4.92 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*=========================================================================

  Program:   Visualization Library
  Module:    FeatEdge.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 "FeatEdge.hh"
#include "vlMath.hh"
#include "Polygon.hh"
#include "FNormals.hh"

Will Schroeder's avatar
Will Schroeder committed
21
22
23
// Description:
// Construct object with feature angle = 30; all types of edges extracted
// and colored.
Will Schroeder's avatar
Will Schroeder committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
vlFeatureEdges::vlFeatureEdges()
{
  this->FeatureAngle = 30.0;
  this->BoundaryEdges = 1;
  this->FeatureEdges = 1;
  this->NonManifoldEdges = 1;
  this->Coloring = 1;
}

// Generate feature edges for mesh
void vlFeatureEdges::Execute()
{
  vlFloatPoints *newPts;
  vlFloatScalars *newScalars;
  vlCellArray *newLines;
Will Schroeder's avatar
Will Schroeder committed
39
  vlPolyData Mesh;
Will Schroeder's avatar
Will Schroeder committed
40
41
42
43
44
45
  int i, j, numNei, cellId;
  int numBEdges, numNonManifoldEdges, numFedges;
  float scalar, n[3], *x1, *x2, cosAngle;
  vlMath math;
  vlPolygon poly;
  int lineIds[2];
Will Schroeder's avatar
Will Schroeder committed
46
  int npts, *pts;
Will Schroeder's avatar
Will Schroeder committed
47
48
49
  vlCellArray *inPolys;
  vlFloatNormals *polyNormals;
  int numPts, nei;
Will Schroeder's avatar
Will Schroeder committed
50
51
  vlIdList neighbors(MAX_CELL_SIZE);
  int p1, p2;
52
  vlPolyData *input=(vlPolyData *)this->Input;
Will Schroeder's avatar
Will Schroeder committed
53
54
55
56
57
58

  vlDebugMacro(<<"Executing feature edges");
  this->Initialize();
//
//  Check input
//
Ken Martin's avatar
Ken Martin committed
59
  if (!(numPts=input->GetNumberOfPoints()) )
Will Schroeder's avatar
Will Schroeder committed
60
61
62
63
64
    {
    vlErrorMacro(<<"No input data!");
    return;
    }

Will Schroeder's avatar
Will Schroeder committed
65
  // build cell structure.  Only operate with polygons.
66
67
  Mesh.SetPoints(input->GetPoints());
  inPolys = input->GetPolys();
Will Schroeder's avatar
Will Schroeder committed
68
69
  Mesh.SetPolys(inPolys);
  Mesh.BuildLinks();
Will Schroeder's avatar
Will Schroeder committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
//  Allocate storage for lines/points
//
  newPts = new vlFloatPoints(numPts/10,numPts); // arbitrary allocations size 
  newScalars = new vlFloatScalars(numPts/10,numPts);
  newLines = new vlCellArray(numPts/10);
//
//  Loop over all polygons generating boundary, non-manifold, and feature edges
//
  if (this->BoundaryEdges || this->NonManifoldEdges || this->FeatureEdges) 
    {
    if ( this->FeatureEdges ) 
      {    
      polyNormals = new vlFloatNormals(inPolys->GetNumberOfCells());

      for (cellId=0, inPolys->InitTraversal(); inPolys->GetNextCell(npts,pts); 
      cellId++)
        {
88
        poly.ComputeNormal(input->GetPoints(),npts,pts,n);
Will Schroeder's avatar
Will Schroeder committed
89
90
91
92
93
94
95
96
97
98
99
100
        polyNormals->InsertNormal(cellId,n);
        }

      cosAngle = cos ((double) math.DegreesToRadians() * this->FeatureAngle);
      }

    numBEdges = numNonManifoldEdges = numFedges = 0;
    for (cellId=0, inPolys->InitTraversal(); inPolys->GetNextCell(npts,pts); 
    cellId++)
      {
      for (i=0; i < npts; i++) 
        {
Will Schroeder's avatar
Will Schroeder committed
101
102
103
        p1 = pts[i];
        p2 = pts[(i+1)%npts];
        Mesh.GetCellEdgeNeighbors(cellId,p1,p2,neighbors);
Will Schroeder's avatar
Will Schroeder committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

        if ( (numNei=neighbors.GetNumberOfIds()) < 1 && this->BoundaryEdges )
          {
          numBEdges++;
          scalar = 0.0;
          }
        else if ( numNei > 1 && this->NonManifoldEdges )
          {
          // check to make sure that this edge hasn't been created before
          for (j=0; j < numNei; j++)
            if ( neighbors.GetId(j) < cellId )
              break;
          if ( j >= numNei )
            {
            numNonManifoldEdges++;
            scalar = 0.33333;
            }
          }
        else if ( numNei == 1 && (nei=neighbors.GetId(0)) > cellId ) 
          {
          if ( math.Dot(polyNormals->GetNormal(nei),polyNormals->GetNormal(cellId)) <= cosAngle ) 
            {
            numFedges++;
            scalar = 0.66667;
            }
          else
            {
            continue;
            }
          }

Will Schroeder's avatar
Will Schroeder committed
135
136
        x1 = Mesh.GetPoint(p1);
        x2 = Mesh.GetPoint(p2);
Will Schroeder's avatar
Will Schroeder committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

        lineIds[0] = newPts->InsertNextPoint(x1);
        lineIds[1] = newPts->InsertNextPoint(x2);

        newLines->InsertNextCell(2,lineIds);

        newScalars->InsertScalar(lineIds[0], scalar);
        newScalars->InsertScalar(lineIds[1], scalar);
        }
      }
    vlDebugMacro(<<"Created " << numBEdges << " boundary edges, " <<
                 numNonManifoldEdges << " non-manifold edges, " <<
                 numFedges << " feature edges");
    if ( this->FeatureEdges ) delete polyNormals;
    }
//
//  Update ourselves.
//
  this->SetPoints(newPts);
  this->SetLines(newLines);
  if ( this->Coloring )
    this->PointData.SetScalars(newScalars);
  else
    delete newScalars;
}

void vlFeatureEdges::PrintSelf(ostream& os, vlIndent indent)
{
165
166
167
168
169
170
171
  vlPolyToPolyFilter::PrintSelf(os,indent);

  os << indent << "Feature Angle: " << this->FeatureAngle << "\n";
  os << indent << "BoundaryEdges: " << (this->BoundaryEdges ? "On\n" : "Off\n");
  os << indent << "FeatureEdges: " << (this->FeatureEdges ? "On\n" : "Off\n"); 
  os << indent << "Non-Manifold Edges: " << (this->NonManifoldEdges ? "On\n" : "Off\n");
  os << indent << "Coloring: " << (this->Coloring ? "On\n" : "Off\n");
Will Schroeder's avatar
Will Schroeder committed
172
173
}