1 /*
2  * NodeNurbsPositionInterpolator.h
3  *
4  * Copyright (C) 1999 Stephen F. White, 2004, 2019 J. "MUFTI" Scheurich
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (see the file "COPYING" for details); if
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  */
21 
22 #pragma once
23 
24 #include "ProtoMacros.h"
25 #include "Proto.h"
26 #include "NurbsCurve.h"
27 #include "SFMFTypes.h"
28 
29 class Mesh;
30 class NodeNurbsCurve;
31 
32 class ProtoNurbsPositionInterpolator : public Proto {
33 public:
34                     ProtoNurbsPositionInterpolator(Scene *scene);
35     virtual Node   *create(Scene *scene);
36 
getType()37     virtual int     getType() const { return VRML_NURBS_POSITION_INTERPOLATOR; }
getNodeClass()38     int             getNodeClass() const
39                        { return CHILD_NODE | INTERPOLATOR_NODE; }
showFields()40     virtual bool    showFields() { return true; }
41 
42     FieldIndex      dimension;
43     FieldIndex      controlPoint;
44     FieldIndex      weight;
45     FieldIndex      knot;
46     FieldIndex      order;
47 };
48 
49 class NodeNurbsPositionInterpolator : public Node, NurbsCurve {
50 public:
51                     NodeNurbsPositionInterpolator(Scene *scene, Proto *proto);
52                     ~NodeNurbsPositionInterpolator();
getX3dVersion(void)53     virtual int     getX3dVersion(void) const { return 0; }
copy()54     virtual Node   *copy() const
55                        { return new NodeNurbsPositionInterpolator(*this); }
56 
57     virtual void    draw();
58     virtual void    drawHandles(void);
59 
60     virtual Vec3f   getHandle(int handle, int *constraint, int *field);
61     virtual void    setHandle(int handle, const Vec3f &v);
62 
63     virtual void    setField(int index, FieldValue *value, int cf = -1);
64 
65     virtual void    flip(int index);
66     virtual void    swap(int fromTo);
67 
maySetDefault(void)68     virtual bool    maySetDefault(void) { return false; }
69 
avoidProtoOnPureVrml(void)70     virtual bool    avoidProtoOnPureVrml(void) { return true; }
71     virtual int     writeProto(int filedes);
72     int             write(int filedes, int indent, bool avoidUse = false);
73 
74     void            createNurbsCurve();
75 
76     virtual Node   *toNurbsCurve(void);
77 
78     void            receiveEvent(int eventIn, double timestamp,
79                                  FieldValue *value);
80 
update()81     void            update() { m_nurbsCurveDirty = true; }
82 
83     MFVec3f        *getControlPoints(void);
84     void            setControlPoints(const MFVec3f *points);
85 
86     fieldMacros(SFInt32, dimension,         ProtoNurbsPositionInterpolator)
87     fieldMacros(SFNode,  controlPoint,      ProtoNurbsPositionInterpolator)
88     fieldMacros(MFDouble, weight,           ProtoNurbsPositionInterpolator)
89     fieldMacros(MFDouble, knot,             ProtoNurbsPositionInterpolator)
90     fieldMacros(SFInt32, order,             ProtoNurbsPositionInterpolator)
91 
92 protected:
93     NodeNurbsCurve *m_nurbsCurve;
94     bool            m_nurbsCurveDirty;
95     MyArray<float>  m_chain;
96     float           m_chainLength;
97     FieldIndex      m_set_fractionField;
98     FieldIndex      m_value_changedField;
99 };
100 
101