SmallChange  1.0.0
A collection of extensions to Coin3D
Loading...
Searching...
No Matches
CubicSplineEngine.h
1#ifndef CUBICSPLINEENGINE_H
2#define CUBICSPLINEENGINE_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/engines/SoSubEngine.h>
37#include <Inventor/engines/SoEngineOutput.h>
38#include <Inventor/fields/SoMFVec3f.h>
39#include <Inventor/fields/SoSFBool.h>
40#include <Inventor/fields/SoSFTime.h>
41#include <Inventor/fields/SoSFFloat.h>
42#include <Inventor/fields/SoMFFloat.h>
43#include <Inventor/fields/SoSFEnum.h>
44#include <Inventor/fields/SoSFMatrix.h>
45#include <Inventor/fields/SoMFRotation.h>
46#include <Inventor/fields/SoSFVec3d.h>
47#include <Inventor/lists/SbList.h>
48#include <Inventor/lists/SoCallbackList.h>
49#include <Inventor/SbMatrix.h>
50#include <Inventor/lists/SbList.h>
51#include <SmallChange/misc/SbCubicSpline.h>
52
53#include <SmallChange/basic.h>
54
55
56class SMALLCHANGE_DLL_API CubicSplineEngine : public SoEngine {
57 typedef SoEngine inherited;
58
59 SO_ENGINE_HEADER(CubicSplineEngine);
60
61public:
62
63 enum Type {
64 CATMULL_ROM = 0,
65 B_SPLINE,
66 BEZIER,
67 GENERIC
68 };
69
70 void setVerifyCallback(void (*cb)(SbVec3d &));
71 void setLinear(const SbBool onoff) {
72 this->linear = onoff;
73 }
74
75 SoSFTime timeIn;
76
77 SoMFVec3f controlpoint;
78 SoMFRotation orientation;
79 SoMFFloat orientationTime;
80 SoSFMatrix basisMatrix; // only valid when type == GENERIC
81 SoSFFloat duration;
82 SoSFBool on;
83 SoSFBool loop;
84 SoSFEnum type;
85 SoSFVec3d offset;
86
87 SoEngineOutput pointOut; // SoSFVec3d
88 SoEngineOutput tangentOut; // SoSFVec3f
89 SoEngineOutput orientationOut; // SoSFRotation
90 SoEngineOutput syncOut; // SoSFTrigger
91
92 static void initClass(void);
94
95 void addEvaluateCallback(void (*callback)(void *, CubicSplineEngine *), void * userdata);
96 void removeEvaluateCallback(void (*callback)(void *, CubicSplineEngine *), void * userdata);
97 void clearEvaluateCallbacks(void);
98
99protected:
100
101 virtual ~CubicSplineEngine();
102
103private:
104
105 virtual void evaluate();
106 virtual void inputChanged(SoField * which);
107
108 void activate(const SbBool onoff);
109 SbCubicSpline currspline;
110 double currtime;
111 double currduration;
112 double starttime;
113 SoCallbackList cblist;
114 SbList <SbVec3f> currpt;
115 SbBool first;
116 SbBool linear;
117
118 void (*verifycb)(SbVec3d & pos);
119};
120
121
122#endif // CUBICSPLINEENGINE_H
Definition CubicSplineEngine.h:56
Definition SbCubicSpline.h:44