File: vtkQuadric.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (98 lines) | stat: -rw-r--r-- 2,857 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQuadric.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkQuadric.h"
#include "vtkObjectFactory.h"


vtkStandardNewMacro(vtkQuadric);

// Construct quadric with all coefficients = 1.
vtkQuadric::vtkQuadric()
{
  for ( int i = 0; i < 10; i++ )
    {
    this->Coefficients[i] = 1.0;
    }
}

// Set the 10 coefficients of the quadric equation.
void vtkQuadric::SetCoefficients(double a[10])
{
  bool changed = false;

  // Check if at least one coefficient really changed
  for ( int i = 0; i < 10; i++ )
    {
    if ( a[i] != this->Coefficients[i] )
      {
      changed = true;
      break;
      }
    }

  if ( changed )
    {
    memcpy(this->Coefficients, a, 10 * sizeof(double));
    this->Modified();
    }
}

// Set the 10 coefficients of the quadric equation.
void vtkQuadric::SetCoefficients(double a0, double a1, double a2, double a3, double a4,
                                double a5, double a6, double a7, double a8, double a9)
{
  double a[10];

  a[0] = a0; a[1] = a1; a[2] = a2; a[3] = a3; a[4] = a4;
  a[5] = a5; a[6] = a6; a[7] = a7; a[8] = a8; a[9] = a9;

  vtkQuadric::SetCoefficients(a);
}

// Evaluate quadric equation.
double vtkQuadric::EvaluateFunction(double x[3])
{
  double *a = this->Coefficients;
  return ( a[0]*x[0]*x[0] + a[1]*x[1]*x[1] + a[2]*x[2]*x[2] +
           a[3]*x[0]*x[1] + a[4]*x[1]*x[2] + a[5]*x[0]*x[2] +
           a[6]*x[0] + a[7]*x[1] + a[8]*x[2] + a[9] );
}

// Evaluate the gradient to the quadric equation.
void vtkQuadric::EvaluateGradient(double x[3], double n[3])
{
  double *a = this->Coefficients;

  n[0] = 2.0*a[0]*x[0] + a[3]*x[1] + a[5]*x[2] + a[6];
  n[1] = 2.0*a[1]*x[1] + a[3]*x[0] + a[4]*x[2] + a[7];
  n[2] = 2.0*a[2]*x[2] + a[4]*x[1] + a[5]*x[0] + a[8];
}

void vtkQuadric::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "Coefficients: "
     << "\n\ta0: " << this->Coefficients[0]
     << "\n\ta1: " << this->Coefficients[1]
     << "\n\ta2: " << this->Coefficients[2]
     << "\n\ta3: " << this->Coefficients[3]
     << "\n\ta4: " << this->Coefficients[4]
     << "\n\ta5: " << this->Coefficients[5]
     << "\n\ta6: " << this->Coefficients[6]
     << "\n\ta7: " << this->Coefficients[7]
     << "\n\ta8: " << this->Coefficients[8]
     << "\n\ta9: " << this->Coefficients[9] << "\n";
}