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/SoSFInt32.h> 00029 #include <Inventor/fields/SoSFUShort.h> 00030 #include <Inventor/fields/SoSFUInt32.h> 00031 #include <Inventor/fields/SoSFColor.h> 00032 #include <Inventor/fields/SoMFVec2f.h> 00033 #include <Inventor/fields/SoSFBool.h> 00034 #include <Inventor/fields/SoSFFloat.h> 00035 #include <Inventor/SbEventHandler.h> 00036 #include <Inventor/SbEventArg.h> 00037 00213 class SoPolyLineScreenDrawer : public SoScreenDrawer 00214 { 00215 SO_NODE_HEADER( SoPolyLineScreenDrawer ); 00216 00217 public: 00219 SoPolyLineScreenDrawer(); 00220 00225 SoSFUInt32 simplificationThreshold; 00226 00235 SoSFBool doCCW; 00236 00238 SoSFColor color; 00239 00241 SoMFVec2f point; 00242 00248 SoSFBool isClosed; 00249 00261 SoSFUShort linePattern; 00262 00268 SoSFInt32 linePatternScaleFactor; 00269 00278 SoSFFloat lineWidth; 00279 00285 struct EventArg : public SbEventArg 00286 { 00288 EventArg( SoHandleEventAction* action, SoPolyLineScreenDrawer* drawer ) 00289 : m_action( action ), m_drawer( drawer ) 00290 {} 00291 00293 ~EventArg() { } 00294 00296 SoHandleEventAction* getAction() const { return m_action; } 00297 00299 SoPolyLineScreenDrawer* getSource() const { return m_drawer; } 00300 00301 private: 00303 SoHandleEventAction* m_action; 00304 00306 SoPolyLineScreenDrawer* m_drawer; 00307 }; 00308 00316 SbEventHandler<const EventArg&> onStart; 00317 00325 SbEventHandler<const EventArg&> onMove; 00326 00334 SbEventHandler<EventArg&> onFinish; 00335 00337 virtual void clear() { point.deleteValues(0); } 00338 00345 virtual void reset(); 00346 00347 private: 00348 00350 static void initClass(); 00351 00353 static void exitClass(); 00354 00356 void addPoint( const SbVec2f& point ); 00357 00362 void removePoint( unsigned id ); 00363 00368 void setPoint( unsigned id, const SbVec2f& newPoint); 00369 00374 void finalize( SoHandleEventAction* action ); 00375 00376 private: 00377 00379 virtual ~SoPolyLineScreenDrawer(); 00380 00381 private: 00382 00384 static void simplify( std::vector<SbVec2f>& polyline, float epsilon ); 00385 00387 static bool isCCW( const std::vector<SbVec2f>& polyline ); 00388 00390 static void makeCCW( std::vector<SbVec2f>& polyline ); 00391 00392 private: 00393 00395 SoSeparator* m_lineRoot; 00396 00397 // Engine used to convert from MFVec2 to MFVec3. it is used only internally by 00398 // this class to draw line in screen space and should not be used by everyone 00399 // else, so it is defined in in SoPolyLineScreenDrawer.cxx file. 00400 00402 class MFVec2ToMFVec3; 00404 MFVec2ToMFVec3* m_vec2ToVec3; 00405 }; 00406 00407 00408 #endif // _SO_POLY_LINE_SCREEN_DRAWER_H_ 00409 00410 00411