Mudbox/nurbs.h Source File

nurbs.h
Go to the documentation of this file.
1 
2 //**************************************************************************/
3 // Copyright (c) 2008 Autodesk, Inc.
4 // All rights reserved.
5 //
6 // Use of this software is subject to the terms of the Autodesk license
7 // agreement provided at the time of installation or download, or which
8 // otherwise accompanies this software in either electronic or hard copy form.
9 //
10 //**************************************************************************/
11 // DESCRIPTION:
12 // CREATED: August 2009
13 //**************************************************************************/
14 
15 namespace mudbox {
16 
18 {
19 public:
21 
22  NURBSCurve( int iDegree = 2, bool bFalloff = false );
23  ~NURBSCurve( void );
24 
25  inline bool operator ==( const NURBSCurve & ) const throw() { return false; };
26  inline bool operator !=( const NURBSCurve &v ) const throw() { return !operator ==( v ); };
27 
28  void SetVisible( bool bVisible ) { m_bVisible = bVisible; };
29  bool Visible( void ) { return m_bVisible; };
30  bool AddCP( const Vector &v, int iIndex = -1 );
31  void RemoveCP( unsigned int iIndex );
32  void MoveCP( unsigned int iIndex, const Vector &v );
33  void Interpolate( const QList<CurvePoint> &points );
34  void RecalcKnots( void );
35  int GetDegree( void ) { return m_iDegree; };
36  void SetDegree( int iDegree );
37  Matrix GetMatrix( void );
38  void Display( bool bScreen = true );
39  virtual void Render();
40  void Recalculate();
41  void ProjectPoint( const Vector &vOrig, float fGuess, float &u, Vector &vProjected, float fMin = 0.001f, float fMax = 0.001f, int iMaxTry = 100 ) const;
42  void BasisFunction( float u, int i, Store<float> &N ) const;
43  void DeriveBasisFunction( int n, float u, int span, Store< Store<float> > &aDerF ) const;
44  int FindSpan( float u ) const;
45  void DeriveAt( float u, int iDeg, Store<Vector> &aDerivs ) const;
46  inline float GetMaxParam( void ) const
47  {
48  if( m_aKnots.ItemCount() == 0 )
49  return 0.0f;
50  return m_aKnots[m_aKnots.ItemCount()-1];
51  };
52  inline Vector operator()( float u ) const
53  {
54  Vector v;
55  if( m_iCPs <= m_iDegree )
56  return v;
57 
58  Store<float> aN( "NURBSCurve temp" );
59  int iSpan = FindSpan(u);
60  BasisFunction( u, iSpan, aN );
61 
62  for( int i = m_iDegree; i >= 0; --i )
63  {
64  v += aN[i] * m_aCPs[iSpan-m_iDegree+i];
65  };
66  return v;
67  };
68  void Serialize( Stream &s );
69  inline Vector TransformToWorld( const Vector &v )
70  {
71  Matrix m = GetMatrix();
72  return m.Transform( v );
73  };
74  inline Vector TransformToLocal( const Vector &v )
75  {
76  Matrix m = GetMatrix();
77  m.Invert();
78  return m.Transform( v );
79  };
80  inline NURBSCurve &operator =( const NURBSCurve &c )
81  {
82  m_iDegree = c.m_iDegree;
83  m_iCPs = c.m_iCPs;
84  m_iSelectedCP = c.m_iSelectedCP;
85  m_bEdited = c.m_bEdited;
86  m_bVisible = c.m_bVisible;
87  m_bClosed = c.m_bClosed;
88  m_bPrecalculated = c.m_bPrecalculated;
89  m_fTotalLength = c.m_fTotalLength;
90  m_fPosX = c.m_fPosX;
91  m_fPosY = c.m_fPosY;
92  m_fAngle = c.m_fAngle;
93  m_fScale = c.m_fScale;
94  m_sName = c.m_sName;
95  if( !m_pFalloff && c.m_pFalloff )
96  m_pFalloff = new NURBSCurve( 3, false );
97  if( c.m_pFalloff )
98  *m_pFalloff = *(c.m_pFalloff);
99  c.m_aCPs.Clone( m_aCPs );
100  c.m_aKnots.Clone( m_aKnots );
101  c.m_aPrecalc.Clone( m_aPrecalc );
102  return *this;
103  };
104  void PrecalculateValues( void );
105  virtual void CalculateChordLengths( void );
106  float GetChordPos( float fLength );
107  void Close( void );
108 
109  int m_iCPs, m_iSelectedCP;
110  bool m_bEdited, m_bVisible, m_bClosed, m_bPrecalculated;
112  float m_fPosX, m_fPosY, m_fAngle, m_fScale;
119 
120 protected:
121 
122  struct ChordLength
123  {
124  ChordLength( float fPos = 0.0f, float fLength = 0.0f ) {m_fPos = fPos; m_fLength = fLength;};
125  float m_fPos, m_fLength;
126  };
127  virtual void CalculateChordLength( float fStart, float fEnd );
129 };
130 
132 {
133 public:
134  NURBSCurveEditor( NURBSCurve *pCurve );
135  ~NURBSCurveEditor( void );
136  void Refresh( void );
137  void OnMouseClick( float fX, float fY );
138  void OnMouseRelease( float fX, float fY );
139  void OnMouseMove( float fX, float fY );
140  void OnDelete( void );
141  void MoveCPTo( const Vector &v );
142 
144  Vector m_vDragDistance, m_vStartDrag;
145 };
146 
147 
148 MBDLL_DECL AttributeWidget *CreateNewCurveWidget( QWidget *pParent, int iWidth, Attribute *pAttribute, bool bAddSnapAndStoreTo = true,
149  bool bInAdjustColor = false );
150 
151 class AttributeCurvePointer : public AttributePointer<NURBSCurve>
152 {
153  AttributeWidget *CreateEditorWidget( QWidget *pParent, int iWidth ) { return CreateNewCurveWidget( pParent, iWidth, this ); };
154 
155 public:
156  AttributeCurvePointer( Node *pOwner = 0, const QString &sID = "") : AttributePointer<NURBSCurve>( pOwner, sID ) { };
157 
158  void SetPointerValue( NURBSCurve *cValue, bool bX = false );
159 };
160 
162 
163 }; // end of namespace mudbox
Store< float > m_aPrecalc
Definition: nurbs.h:116
int GetDegree(void)
Definition: nurbs.h:35
Represents a 3D vector or point with S23E8 floating point elements.
Definition: math.h:35
float m_fAngle
Definition: nurbs.h:112
typedefQT_END_NAMESPACE QT_END_HEADER struct _XDisplay Display
Definition: qwindowdefs.h:115
float m_fTotalLength
Definition: nurbs.h:111
Base class for Curve types.
Definition: curve.h:20
bool m_bPrecalculated
Definition: nurbs.h:110
float GetMaxParam(void) const
Definition: nurbs.h:46
Vector operator()(float u) const
Definition: nurbs.h:52
Vector TransformToLocal(const Vector &v)
Definition: nurbs.h:74
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
Matrix & Invert(bool *pOk=0)
Inverts the matrix and returns it.
bool operator==(const Attribute &cA, const AttributeInstance< type > &cB)
This operator compares the two attributes and NOT their values.
Definition: node.h:577
void SetVisible(bool bVisible)
Sets the node visibility Should be overridden in derived classes.
Definition: nurbs.h:28
QString m_sName
Definition: nurbs.h:113
This class represents a 4x4 transformation matrix.
Definition: math.h:1122
NURBSCurve * m_pFalloff
Definition: nurbs.h:117
Store< float > m_aKnots
Definition: nurbs.h:115
GLenum GLsizei n
Definition: GLee.h:3432
bool operator!=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:533
const GLdouble * v
Definition: GLee.h:1174
Store< ChordLength > m_aChordLengths
Definition: nurbs.h:128
Vector Transform(const Vector &v, float fW=1.0f) const
Transforms a vector by the matrix and returns the result.
Definition: math.h:1219
Store Clone(void) const
Returns a copy of this array. The returned copy will have a duplicate of all data in the original...
Definition: array.h:386
float m_fScale
Definition: nurbs.h:112
const GLubyte * c
Definition: GLee.h:5419
Class: ConvolutionKernel.
Definition: array.h:15
This is an abstract base structure for all attributes.
Definition: node.h:181
bool Visible(void)
Definition: nurbs.h:29
Vector TransformToWorld(const Vector &v)
Definition: nurbs.h:69
Store< Vector > m_aCPs
Definition: nurbs.h:114
Streams are used to read information from a file, or to write it to a file.
Definition: stream.h:39
GLsizei const GLfloat * points
Definition: GLee.h:3793
GLenum GLenum GLvoid GLvoid GLvoid * span
Definition: GLee.h:893
NURBSCurve * m_pCurve
Definition: nurbs.h:143
AttributeCurvePointer(Node *pOwner=0, const QString &sID="")
Definition: nurbs.h:156
GLdouble s
Definition: GLee.h:1173
MBDLL_DECL AttributeWidget * CreateNewCurveWidget(QWidget *pParent, int iWidth, Attribute *pAttribute, bool bAddSnapAndStoreTo=true, bool bInAdjustColor=false)
GLclampf f
Definition: GLee.h:9303
AttributeCurvePointer acurveptr
Definition: nurbs.h:161
void SetPointerValue(NURBSCurve *cValue, bool bX=false)
#define MBDLL_DECL
Definition: dllinterface.h:35
This class can be used instead of standard pointers, when the pointer target class is derived from th...
Definition: node.h:601