Update suitable examples and tests to use blank mode
[shapes.git] / source / pathslider3D.cc
blobb73fc9624496e8440bcddc0cc39cd8863a13e303
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2009 Henrik Tidefelt
19 #include <cmath>
21 #include "shapestypes.h"
22 #include "shapesexceptions.h"
23 #include "astexpr.h"
24 #include "consts.h"
25 #include "globals.h"
26 #include "bezier.h"
28 #include <ctype.h>
29 #include <stack>
30 #include <algorithm>
32 using namespace Shapes;
33 using namespace std;
36 Lang::PathSlider3D::PathSlider3D( const Lang::PathSlider3D & orig )
37 : path_( orig.getPath( ) ), t_( orig.getTime( ) ), info_( orig.getInfo( ) )
38 { }
40 Lang::PathSlider3D::PathSlider3D( const RefCountPtr< const Lang::ElementaryPath3D > & path )
41 : path_( path ), t_( 0 ), info_( Kernel::THE_VOID_VARIABLE )
42 { }
44 Lang::PathSlider3D::PathSlider3D( const RefCountPtr< const Lang::ElementaryPath3D > & path, Concrete::SplineTime t )
45 : path_( path ), t_( t ), info_( Kernel::THE_VOID_VARIABLE )
46 { }
48 Lang::PathSlider3D::PathSlider3D( const RefCountPtr< const Lang::ElementaryPath3D > & path, Concrete::SplineTime t, Kernel::VariableHandle info )
49 : path_( path ), t_( t ), info_( info )
50 { }
52 DISPATCHIMPL( PathSlider3D );
54 Lang::PathSlider3D::~PathSlider3D( )
55 { }
57 RefCountPtr< const Lang::Class > Lang::PathSlider3D::TypeID( new Lang::SystemFinalClass( strrefdup( "PathSlider3D" ) ) );
58 TYPEINFOIMPL( PathSlider3D );
60 Kernel::VariableHandle
61 Lang::PathSlider3D::getField( const char * fieldID, const RefCountPtr< const Lang::Value > & selfRef ) const
63 if( strcmp( fieldID, "p" ) == 0 )
65 return Kernel::VariableHandle( new Kernel::Variable( point( ) ) );
67 if( strcmp( fieldID, "v" ) == 0 )
69 return Kernel::VariableHandle( new Kernel::Variable( speed( ) ) );
71 if( strcmp( fieldID, "rv" ) == 0 )
73 return Kernel::VariableHandle( new Kernel::Variable( reverse_speed( ) ) );
75 if( strcmp( fieldID, "T" ) == 0 )
77 return Kernel::VariableHandle( new Kernel::Variable( direction( ) ) );
79 if( strcmp( fieldID, "rT" ) == 0 )
81 return Kernel::VariableHandle( new Kernel::Variable( reverse_direction( ) ) );
83 if( strcmp( fieldID, "N" ) == 0 )
85 return Kernel::VariableHandle( new Kernel::Variable( normal( ) ) );
87 if( strcmp( fieldID, "rN" ) == 0 )
89 return Kernel::VariableHandle( new Kernel::Variable( reverse_normal( ) ) );
91 if( strcmp( fieldID, "B" ) == 0 )
93 return Kernel::VariableHandle( new Kernel::Variable( binormal( ) ) );
95 if( strcmp( fieldID, "rB" ) == 0 )
97 return Kernel::VariableHandle( new Kernel::Variable( reverse_binormal( ) ) );
99 if( strcmp( fieldID, "ik" ) == 0 )
101 return Kernel::VariableHandle( new Kernel::Variable( radiusOfCurvature( ) ) );
103 if( strcmp( fieldID, "rik" ) == 0 )
105 return Kernel::VariableHandle( new Kernel::Variable( reverse_radiusOfCurvature( ) ) );
107 if( strcmp( fieldID, "it" ) == 0 )
109 return Kernel::VariableHandle( new Kernel::Variable( radiusOfTorsion( ) ) );
111 if( strcmp( fieldID, "rit" ) == 0 )
113 return Kernel::VariableHandle( new Kernel::Variable( reverse_radiusOfTorsion( ) ) );
115 if( strcmp( fieldID, "time" ) == 0 )
117 return Kernel::VariableHandle( new Kernel::Variable( time( ) ) );
119 if( strcmp( fieldID, "length" ) == 0 )
121 return Kernel::VariableHandle( new Kernel::Variable( length( ) ) );
123 if( strcmp( fieldID, "past" ) == 0 )
125 if( t_.isPast( ) )
127 return Kernel::THE_TRUE_VARIABLE;
129 return Kernel::THE_FALSE_VARIABLE;
131 if( strcmp( fieldID, "looped" ) == 0 )
133 if( t_.t( ) > Concrete::Time( path_->duration( ) ) ||
134 t_.t( ) < Concrete::Time( 0 ) )
136 return Kernel::THE_TRUE_VARIABLE;
138 return Kernel::THE_FALSE_VARIABLE;
140 if( strcmp( fieldID, "mod" ) == 0 )
142 return Helpers::newValHandle( new Lang::PathSlider3D( path_, modPhysical( t_.t( ), Concrete::Time( path_->duration( ) ) ) ) );
144 if( strcmp( fieldID, "info" ) == 0 )
146 return info_;
148 throw Exceptions::NonExistentMember( getTypeName( ), fieldID );
151 RefCountPtr< Lang::PathSlider3D >
152 Lang::PathSlider3D::move_time( const Concrete::Time delta ) const
154 Concrete::Time newTime = t_.t( ) + delta;
155 if( path_->isClosed( ) )
157 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, newTime ) );
159 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_,
160 Concrete::SplineTime( newTime,
161 Concrete::Time( 0 ) <= newTime &&
162 newTime <= Concrete::Time( path_->duration( ) ) ) ) );
165 RefCountPtr< Lang::PathSlider3D >
166 Lang::PathSlider3D::move_length( const Concrete::Length delta ) const
168 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, path_->arcTime( delta, t_.t( ) ) ) );
171 RefCountPtr< Lang::PathSlider3D >
172 Lang::PathSlider3D::seek_time( const Concrete::Time newTime ) const
174 if( path_->isClosed( ) )
176 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, newTime ) );
178 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_,
179 Concrete::SplineTime( newTime,
180 Concrete::Time( 0 ) <= newTime &&
181 newTime <= Concrete::Time( path_->duration( ) ) ) ) );
184 RefCountPtr< Lang::PathSlider3D >
185 Lang::PathSlider3D::seek_start( ) const
187 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, Concrete::Time( 0. ) ) );
190 RefCountPtr< Lang::PathSlider3D >
191 Lang::PathSlider3D::seek_end( ) const
193 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, Concrete::Time( path_->duration( ) ) ) );
196 RefCountPtr< Lang::PathSlider3D >
197 Lang::PathSlider3D::seek_length( const Concrete::Length val ) const
199 return RefCountPtr< Lang::PathSlider3D >( new Lang::PathSlider3D( path_, path_->arcTime( val ) ) );
203 RefCountPtr< const Lang::Coords3D >
204 Lang::PathSlider3D::point( ) const
206 return path_->point( t_.t( ) );
209 RefCountPtr< const Lang::Length >
210 Lang::PathSlider3D::speed( ) const
212 return path_->speed( t_.t( ) );
215 RefCountPtr< const Lang::Length >
216 Lang::PathSlider3D::reverse_speed( ) const
218 return path_->reverse_speed( t_.t( ) );
221 RefCountPtr< const Lang::FloatTriple >
222 Lang::PathSlider3D::direction( ) const
224 return path_->direction( t_.t( ) );
227 RefCountPtr< const Lang::FloatTriple >
228 Lang::PathSlider3D::reverse_direction( ) const
230 return path_->reverse_direction( t_.t( ) );
233 RefCountPtr< const Lang::FloatTriple >
234 Lang::PathSlider3D::normal( ) const
236 return path_->normal( t_.t( ) );
239 RefCountPtr< const Lang::FloatTriple >
240 Lang::PathSlider3D::reverse_normal( ) const
242 return path_->reverse_normal( t_.t( ) );
245 RefCountPtr< const Lang::FloatTriple >
246 Lang::PathSlider3D::binormal( ) const
248 RefCountPtr< const Lang::FloatTriple > tmp_T = path_->direction( t_.t( ) );
249 RefCountPtr< const Lang::FloatTriple > tmp_N = path_->normal( t_.t( ) );
250 return RefCountPtr< const Lang::FloatTriple >( new Lang::FloatTriple( Lang::cross( *tmp_T, *tmp_N ) ) );
253 RefCountPtr< const Lang::FloatTriple >
254 Lang::PathSlider3D::reverse_binormal( ) const
256 RefCountPtr< const Lang::FloatTriple > tmp_T = path_->reverse_direction( t_.t( ) );
257 RefCountPtr< const Lang::FloatTriple > tmp_N = path_->reverse_normal( t_.t( ) );
258 return RefCountPtr< const Lang::FloatTriple >( new Lang::FloatTriple( Lang::cross( *tmp_T, *tmp_N ) ) );
261 RefCountPtr< const Lang::Length >
262 Lang::PathSlider3D::radiusOfCurvature( ) const
264 return path_->radiusOfCurvature( t_.t( ) );
267 RefCountPtr< const Lang::Length >
268 Lang::PathSlider3D::reverse_radiusOfCurvature( ) const
270 return path_->reverse_radiusOfCurvature( t_.t( ) );
273 RefCountPtr< const Lang::Length >
274 Lang::PathSlider3D::radiusOfTorsion( ) const
276 return path_->radiusOfTorsion( t_.t( ) );
279 RefCountPtr< const Lang::Length >
280 Lang::PathSlider3D::reverse_radiusOfTorsion( ) const
282 return path_->reverse_radiusOfTorsion( t_.t( ) );
285 RefCountPtr< const Lang::Float >
286 Lang::PathSlider3D::time( ) const
288 return RefCountPtr< const Lang::Float >( new Lang::Float( t_.t( ).offtype< 0, 1 >( ) ) );
291 RefCountPtr< const Lang::Length >
292 Lang::PathSlider3D::length( ) const
294 return RefCountPtr< const Lang::Length >( new Lang::Length( path_->arcLength( t_.t( ) ) ) );
298 void
299 Lang::PathSlider3D::show( std::ostream & os ) const
301 os << "Path slider " ;
302 if( this->getRear( ) != NullPtr< const Lang::Value >( ) )
304 os << "(with rear) " ;
306 if( this->getFront( ) != NullPtr< const Lang::Value >( ) )
308 os << "(with front) " ;
310 os << " at " << t_.t( ).offtype< 0, 1 >( ) ;
311 if( t_.isPast( ) )
313 os << " (past)" ;
315 os << " / " << path_->duration( );
318 void
319 Lang::PathSlider3D::gcMark( Kernel::GCMarkedSet & marked )
321 const_cast< Lang::ElementaryPath3D * >( path_.getPtr( ) )->gcMark( marked );
325 RefCountPtr< const Lang::Value >
326 Lang::PathSlider3D::getRear( ) const
328 return RefCountPtr< const Lang::Value >( NullPtr< const Lang::Value >( ) );
331 RefCountPtr< const Lang::Value >
332 Lang::PathSlider3D::getFront( ) const
334 return RefCountPtr< const Lang::Value >( NullPtr< const Lang::Value >( ) );
338 Lang::PathSlider3D_rear::PathSlider3D_rear( const Lang::PathSlider3D & orig, const RefCountPtr< const Lang::Value > & rear )
339 : PathSlider3D( orig ), rear_( rear )
342 RefCountPtr< const Lang::Value >
343 Lang::PathSlider3D_rear::getRear( ) const
345 return rear_;
348 Lang::PathSlider3D_front::PathSlider3D_front( const Lang::PathSlider3D & orig, const RefCountPtr< const Lang::Value > & front )
349 : PathSlider3D( orig ), front_( front )
352 RefCountPtr< const Lang::Value >
353 Lang::PathSlider3D_front::getFront( ) const
355 return front_;