00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : Thibaut Andrieu (Jan 2011) 00022 **=======================================================================*/ 00023 00024 #if !defined _SO_POLY_LINE_SCREEN_DRAWER_H_ 00025 #define _SO_POLY_LINE_SCREEN_DRAWER_H_ 00026 00027 #include <Inventor/drawers/SoScreenDrawer.h> 00028 #include <Inventor/fields/SoSFUInt32.h> 00029 #include <Inventor/fields/SoSFColor.h> 00030 #include <Inventor/fields/SoMFVec2f.h> 00031 #include <Inventor/fields/SoSFBool.h> 00032 #include <Inventor/SbEventHandler.h> 00033 #include <Inventor/SbEventArg.h> 00034 00210 class SoPolyLineScreenDrawer : public SoScreenDrawer 00211 { 00212 SO_NODE_HEADER( SoPolyLineScreenDrawer ); 00213 00214 public: 00216 SoPolyLineScreenDrawer(); 00217 00222 SoSFUInt32 simplificationThreshold; 00223 00232 SoSFBool doCCW; 00233 00235 SoSFColor color; 00236 00238 SoMFVec2f point; 00239 00245 SoSFBool isClosed; 00246 00252 struct EventArg : public SbEventArg 00253 { 00255 EventArg( SoHandleEventAction* action, SoPolyLineScreenDrawer* drawer ) 00256 : m_action( action ), m_drawer( drawer ) 00257 {} 00258 00260 ~EventArg() { } 00261 00263 SoHandleEventAction* getAction() const { return m_action; } 00264 00266 SoPolyLineScreenDrawer* getSource() const { return m_drawer; } 00267 00268 private: 00270 SoHandleEventAction* m_action; 00271 00273 SoPolyLineScreenDrawer* m_drawer; 00274 }; 00275 00282 SbEventHandler<EventArg&> onFinish; 00283 00285 virtual void clear() { point.deleteValues(0); } 00286 00287 #if 1 00300 typedef SbBool LineDrawerEventCallback( SoHandleEventAction* action, 00301 SoPolyLineScreenDrawer* drawer, 00302 void* userData ); 00303 SoDEPRECATED 00315 virtual void setFinishCallback( LineDrawerEventCallback* callback, 00316 void* userData = NULL ); 00317 #endif 00319 private: 00320 00322 static void initClass(); 00323 00325 static void exitClass(); 00326 00328 void addPoint( const SbVec2f& point ); 00329 00334 void removePoint( unsigned id ); 00335 00340 void setPoint( unsigned id, const SbVec2f& newPoint); 00341 00346 void finalize( SoHandleEventAction* action ); 00347 00348 private: 00349 00351 virtual ~SoPolyLineScreenDrawer(); 00352 00353 private: 00354 00356 static void simplify( std::vector<SbVec2f>& polyline, float epsilon ); 00357 00359 static bool isCCW( const std::vector<SbVec2f>& polyline ); 00360 00362 static void makeCCW( std::vector<SbVec2f>& polyline ); 00363 00364 private: 00365 00367 SoSeparator* m_lineRoot; 00368 00369 // Engine used to convert from MFVec2 to MFVec3. it is used only internally by 00370 // this class to draw line in screen space and should not be used by everyone 00371 // else, so it is defined in in SoPolyLineScreenDrawer.cxx file. 00372 00374 class MFVec2ToMFVec3; 00376 MFVec2ToMFVec3* m_vec2ToVec3; 00377 00379 LineDrawerEventCallback* m_finalizeCallback; 00380 00382 void* m_finalizeCallbackUserData; 00383 00384 }; 00385 00386 00387 #endif // _SO_POLY_LINE_SCREEN_DRAWER_H_ 00388 00389 00390