MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoCSO/SoView2DCSOEditor/SoView2DCSOExtensibleEditor/extensions/SoCSOModifyEditor/SoCSOModifyEditor.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 
00012 #ifndef __SoCSOModifyEditor_H
00013 #define __SoCSOModifyEditor_H
00014 
00015 #include <SoView2DCSOEditor/SoView2DCSOExtensibleEditor/SoCSOEditorExtension.h>
00016 
00018 
00020 class SOCSO_EXPORT SoCSOModifyEditor : public SoCSOEditorExtension
00021 {
00022   SO_NODE_HEADER(SoCSOEllipseEditor);
00023 
00024 public:
00025 
00027   SoCSOModifyEditor();
00028 
00032   SoSFTrigger notifyTrailIsSelfIntersecting;
00035   SoSFTrigger notifyRejectModification;
00038   SoSFBool shouldCheckCSOForSelfIntersection;
00040   SoSFColor selfIntersectionColor;
00043   SoSFBool shouldSetModifiedCSOSelected;
00044 
00046   static void initClass();
00047 
00048   virtual void createStartPressAt(const SoPointerPosition& pos);  
00049   virtual void createDragMoveTo(const SoPointerPosition& pos);
00050   virtual bool createEndPress(int clickCount);
00051 
00052   virtual bool isCreationAllowed() const;
00053 
00054   virtual void draw(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& sliceInfo, SoView2DCSOExtensibleEditor* editor);
00055   // This editor does not actually create CSOs but otherwise the mouse events would not reach this.
00056   virtual bool canCreateCSOs() const { return true; }
00058   virtual bool shouldRenderSpecific(ml::CSO*) const { return false; }
00060   virtual bool shouldRenderGeneral(ml::CSO*) const { return true; }
00061 
00062   // just overload the methods below because they are purely virtual but not used in here
00063   virtual void selectAndMoveStartPressAt(const SoPointerPosition&) {}
00064   virtual void selectAndMoveDragMoveTo(const SoPointerPosition&) {}
00065   virtual SoPointingAction* selectAndMoveEndPress(int) { return NULL; }
00066 
00067   virtual int cursorShape() const { return SoViewerProxy::CROSS_FREEFORM_CURSOR; }
00068 
00071   virtual  bool evaluateHitPoint(const ml::Vector3& , View2DSliceList* , ml::CSOList* , 
00072                                  const ml::CSOBoundingBox& , SoView2DCSOExtensibleEditor* ,
00073                                  ml::CSO*& , ml::CSOSeedPoint*& , 
00074                                  ml::CSOPathPoints*& , float& )
00075   {
00076     return false;
00077   }
00078 
00079 
00080 protected:
00081 
00082 private:
00083 
00084 
00086   struct CSOTrailIntersection
00087   {
00088     CSOTrailIntersection()
00089     {
00090       csoPointsIndex   = 0;
00091       trailPointsIndex = 0;
00092     }
00093     ml::Vector3 intersectionPoint;
00094     size_t csoPointsIndex;
00095     size_t trailPointsIndex;
00096   };
00097 
00099   ml::CSO* getModifyCandidate();
00101   bool isEligibleForModification(ml::CSO* cso) const;
00104   void fillPreCandidatesList(std::vector < ml::CSO* >& candidates);
00107   void fillCandidatesOnSameSlice(const std::vector < ml::CSO* >& candidates, std::vector < ml::CSO* >& candidatesOnSameSlice);
00110   void fillCandidatesCrossedVoxelBoundingBox(const std::vector < ml::CSO* >& candidatesOnSameSlice, std::vector < ml::CSO* >& candidatesCrossedBoundingBox);
00113   void fillCandidatesPointInsideTrailBoundingBox(const std::vector < ml::CSO* >&candidatesCrossedBoundingBox, std::vector < ml::CSO* >& candidatesPointInsideTrailBoundingBox);
00116   void fillCandidatesCrossedByTrail(const std::vector < ml::CSO* >& candidatesPointInsideTrailBoundingBox, std::vector < ml::CSO* >& candidatesCrossingTrail);
00117     
00119   void modifyCandidate(ml::CSO* candidate);
00120 
00121   void addToTrail(const SbVec3f& position);
00122   void convertSbVec3fToVector3(const SbVec3f& original, ml::Vector3& copy) const;
00124   void reverseOrder(std::vector < ml::Vector3 >& positions );
00125 
00127   void smoothPositions(const std::vector < ml::Vector3 >& inputPositions, std::vector < ml::Vector3 >& smoothedTrail);
00130   void fillUpTrail(const std::vector < ml::Vector3 >& inputPositions, std::vector < ml::Vector3 >& filledOutputPositions);
00131 
00132   void setupGLForTrail();
00133   void setBackGLForTrail();
00134 
00137   void floorCeilCSOBoundingBox(ml::CSOBoundingBox& boundingBox);
00138 
00140   bool _isUNIONModification;
00141 
00143   ml::CSOBoundingBox getVoxelBoundingBoxForTrail();
00144 
00146   bool segmentsArePossiblyCrossing(const ml::Vector3& trailSegmentStart, 
00147                                    const ml::Vector3& trailSegmentEnd, 
00148                                    const ml::Vector3& csoSegmentStart, 
00149                                    const ml::Vector3& csoSegmentEnd);
00150 
00151   std::vector < ml::Vector3 > _trailPositions;
00152   std::vector < ml::Vector3 > _trailPositionsVoxelSpace; 
00153   ml::Vector3 _trailNormal;  
00154   ml::CSOBoundingBox _projectedTrailVoxelBoundingBox;
00155 
00156   std::map < ml::CSO* , std::vector < ml::Vector3> > _csoPathPointsVoxelSpace;
00157 
00159   bool contains(const std::vector< ml::CSO* >& csoVector, ml::CSO* cso) const;
00160 
00161   ml::Matrix4 _worldToVoxelMatrix;
00162 };
00163 
00165 
00166 #endif // __SoCSOModifyEditor_H