Add clipping to scilab objects and correct a bug in marks positioning.
Jean-baptiste Silvy [Mon, 16 Jul 2007 14:33:31 +0000 (14:33 +0000)]
60 files changed:
scilab/modules/graphics/includes/math_graphics.h
scilab/modules/graphics/sci_gateway/c/sci_geom3d.c
scilab/modules/graphics/src/c/math_graphics.c
scilab/modules/jvm/LibScilab_Import.def
scilab/modules/jvm/src/c/JniUtils.c
scilab/modules/renderer/graphics_Import.def
scilab/modules/renderer/renderer.vcproj
scilab/modules/renderer/src/cpp/DrawableClippedObject.cpp
scilab/modules/renderer/src/cpp/DrawableClippedObject.h
scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.cpp [new file with mode: 0644]
scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.h [new file with mode: 0644]
scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.cpp [new file with mode: 0644]
scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.h [new file with mode: 0644]
scilab/modules/renderer/src/cpp/DrawableObjectImp.h
scilab/modules/renderer/src/cpp/DrawableObjectJoGL.cpp
scilab/modules/renderer/src/cpp/DrawableObjectJoGL.h
scilab/modules/renderer/src/cpp/figureDrawing/DrawableFigureImp.cpp
scilab/modules/renderer/src/cpp/figureDrawing/DrawableFigureImp.h
scilab/modules/renderer/src/cpp/figureDrawing/DrawableFigureJoGL.cpp
scilab/modules/renderer/src/cpp/figureDrawing/DrawableFigureJoGL.h
scilab/modules/renderer/src/cpp/polylineDrawing/DrawablePolylineBridge.cpp
scilab/modules/renderer/src/cpp/polylineDrawing/DrawablePolylineBridge.h
scilab/modules/renderer/src/cpp/polylineDrawing/DrawablePolylineJoGL.cpp
scilab/modules/renderer/src/cpp/polylineDrawing/DrawablePolylineJoGL.h
scilab/modules/renderer/src/cpp/rectangleDrawing/DrawableRectangle.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/DrawableRectangleImp.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/DrawableRectangleImp.h
scilab/modules/renderer/src/cpp/rectangleDrawing/DrawableRectangleJoGL.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/DrawableRectangleJoGL.h
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleFillDrawerJoGL.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleFillDrawerJoGL.h
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleLineDrawerJoGL.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleLineDrawerJoGL.h
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleMarkDrawerJoGL.cpp
scilab/modules/renderer/src/cpp/rectangleDrawing/RectangleMarkDrawerJoGL.h
scilab/modules/renderer/src/cpp/subwinDrawing/CameraBridgeFactory.h
scilab/modules/renderer/src/cpp/subwinDrawing/CameraFactory.h
scilab/modules/renderer/src/cpp/subwinDrawing/CameraJoGL.cpp
scilab/modules/renderer/src/cpp/subwinDrawing/CameraJoGL.h
scilab/modules/renderer/src/cpp/subwinDrawing/DrawableSubwin.cpp
scilab/modules/renderer/src/cpp/subwinDrawing/DrawableSubwin.h
scilab/modules/renderer/src/cpp/subwinDrawing/DrawableSubwinBridge.h
scilab/modules/renderer/src/cpp/subwinDrawing/DrawableSubwinJoGL.cpp
scilab/modules/renderer/src/cpp/subwinDrawing/DrawableSubwinJoGL.h
scilab/modules/renderer/src/java/org/scilab/modules/renderer/AutoDrawableObjectJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/DrawableClippedObjectJoGL.java [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/DrawableObjectJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/figureDrawing/DrawableFigureJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/rectangleDrawing/DrawableRectangleJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/rectangleDrawing/RectangleLineDrawerJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/rectangleDrawing/RectangleMarkDrawerJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/subwinDrawing/CameraJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/subwinDrawing/DrawableSubwinJoGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/CoordinateTransformation.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Plane3D.java [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Vector3D.java [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3D.java [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3DManager.java [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/GLTools.java [moved from scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/GLTools.java with 91% similarity]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/MovableClipPlane3D.java [new file with mode: 0644]

index 7bcc484..d6169c6 100644 (file)
@@ -166,11 +166,20 @@ void iNormalize2d( int vect[2] ) ;
 #define DOT_PROD_3D(v1,v2) ( ((v1)[0]) * ((v2)[0]) + ((v1)[1]) * ((v2)[1]) + ((v1)[2]) * ((v2)[2]) )
 
 /**
-* Norm of a 3D vector
-*/
+ * Cross product of two vector
+ * @param res v1^v2
+ */
+void crossProduct( const double v1[3], const double v2[3], double res[3] ) ;
+
+/**
+ * Norm of a 3D vector
+ */
 #define NORM_3D(v) ( sqrt( DOT_PROD_3D((v),(v)) ) ) ;
 
-/*----------------------------------------------------------------------------*/
+/**
+ * Normalize a 3D vector
+ */
+void normalize3D( double vect[3] ) ;
 
 /*----------------------------------------------------------------------------*/
 /* check if two values can be considered equal given an accurracy */
index d795398..e349b12 100644 (file)
@@ -28,7 +28,7 @@ int geom3d(double *x, double *y, double *z, integer *n)
 
   if(ppsubwin->logflags[0] =='l')
   {
-    for ( j =0 ; j < (*n) ; j++) {
+    for ( j = 0 ; j < (*n) ; j++ ) {
       if(x[j] <= 0.){
         sciprint("geom3d error : Operation can not be performed because X axis is in logscale mode and the specified x vector has a negative value\n");
         return -1;
index ebbce77..e0da94e 100644 (file)
@@ -141,6 +141,21 @@ void iNormalize2d( int vect[2] )
   vect[1] = round( vect[1] / norm ) ;
 }
 /*----------------------------------------------------------------------------*/
+void crossProduct( const double v1[3], const double v2[3], double res[3] )
+{
+  res[0] = v1[1] * v2[2] - v1[2] * v2[1] ;
+  res[1] = v1[2] * v2[0] - v1[0] * v2[2] ;
+  res[2] = v1[0] * v2[1] - v1[1] * v2[0] ;
+}
+/*----------------------------------------------------------------------------*/
+void normalize3D( double vect[3] )
+{
+  double norm = NORM_3D(vect) ;
+  vect[0] /= norm ;
+  vect[1] /= norm ;
+  vect[2] /= norm ;
+}
+/*----------------------------------------------------------------------------*/
 /* check if two values can be considered equal given an accurracy */
 int safeEqual( double val1, double val2, double accuracy )
 {
index 3abedbb..7f8737e 100644 (file)
@@ -20,4 +20,5 @@ EXPORTS
  createvarfromptr_
  GetXmlFileEncoding
  callFunctionFromGateway
+ sciprint
 ;
index 802a30a..550db1a 100644 (file)
@@ -11,6 +11,7 @@
 #include "JniUtils.h"
 #include "MALLOC.h"
 #include "Scierror.h"
+#include "sciprint.h"
 
 /*------------------------------------------------------------------------------------------*/
 /** Static variable containing the jvm. */
@@ -250,6 +251,7 @@ jvalue jniCallMemberFunctionV( jobject instance, jniCallMethodCache * cache, con
 
     if ( methodId == NULL )
     {
+      jniCheckLastCall(TRUE);
       Scierror( 999, "Error when calling function %s.\r\n", functionName ) ;
       return res;
     }
index 0ea2fbf..0be19ae 100644 (file)
@@ -43,4 +43,7 @@ sciGetMargins
 doubleArrayCopy
 sciGetIsReadyForRendering
 sciGetRealDataBounds
-sciGetViewingAngles
\ No newline at end of file
+sciGetViewingAngles
+sciGetClipping
+sciGetParentSubwin
+sciGetIsClipping
\ No newline at end of file
index ae880a5..6bb01c5 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\src\cpp\DrawableClippedObjectJoGL.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\cpp\compoundDrawing\DrawableCompound.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\src\cpp\figureDrawing\DrawableFigureImp.cpp"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\src\cpp\figureDrawing\DrawableFigureImpFactory.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\src\cpp\polylineDrawing\DrawablePolylineBridge.cpp"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\src\cpp\polylineDrawing\DrawablePolylineBrirdgeFactory.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\src\cpp\subwinDrawing\DrawableSubwinBridge.cpp"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\src\cpp\subwinDrawing\DrawableSubwinBridgeFactory.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\cpp\DrawableClippedObjectBridge.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\cpp\DrawableClippedObjectJoGL.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\cpp\compoundDrawing\DrawableCompound.h"
                                >
                        </File>
index aa3db3a..0e1e59b 100644 (file)
@@ -2,11 +2,16 @@
 /* file: DrawableClippedObject.cpp                                        */
 /* Copyright INRIA 2007                                                   */
 /* Authors : Jean-Baptiste Silvy                                          */
-/* desc : Class wich represent an object wich can be clipped              */
+/* desc : Class which represent an object which can be clipped            */
 /*------------------------------------------------------------------------*/
 
 #include "DrawableClippedObject.h"
 
+extern "C"
+{
+#include "GetProperty.h"
+}
+
 namespace sciGraphics
 {
 
@@ -15,30 +20,88 @@ DrawableClippedObject::DrawableClippedObject( sciPointObj * drawed )
   : DrawableObject( drawed )
 {
   m_bIsClipped = false ;
+  m_bXClippingEnable = false ;
+  m_bYClippingEnable = false ;
+  m_bZClippingEnable = false ;
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObject::setClipBox( void )
+{
+  // compute the real clipping of the object
+  sciPointObj * pObj = getDrawedObject() ;
+
+  switch(sciGetIsClipping(pObj))
+  {
+  case 0: // clipgrf state, use axes bounds
+    {
+      double clipBounds[6] ;
+      sciGetRealDataBounds(sciGetParentSubwin(pObj), clipBounds ) ;
+      setClipBox(clipBounds[0], clipBounds[1], clipBounds[2],
+                 clipBounds[3], clipBounds[4], clipBounds[5] ) ;
+      m_bXClippingEnable = true ;
+      m_bYClippingEnable = true ;
+      m_bZClippingEnable = true ;
+    }
+    break;
+  case 1: // on state, use its own bounds
+    {
+      double * clipBounds = sciGetClipping(pObj) ; // array (x,y,w,h)
+      setClipBox( clipBounds[0], clipBounds[0] + clipBounds[2],
+                  clipBounds[1], clipBounds[1] + clipBounds[3],
+                  0.0, 0.0 ) ;
+      m_bXClippingEnable = true ;
+      m_bYClippingEnable = true ;
+      m_bZClippingEnable = false ;
+    }
+    break;
+  default: // clipping off
+    m_bXClippingEnable = false ;
+    m_bYClippingEnable = false ;
+    m_bZClippingEnable = false ;
+    return;
+  }
+
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableClippedObject::setClipBox( double xMin, double xMax,
                                         double yMin, double yMax,
                                         double zMin, double zMax )
 {
-  m_dXmin = xMin ;
-  m_dXmax = xMax ;
-
-  m_dYmin = yMin ;
-  m_dYmax = yMax ;
-
-  m_dZmin = zMin ;
-  m_dZmax = zMax ;
+  getClippedObjBridge()->setClipBox(xMin, xMax, yMin, yMax, zMin, zMax) ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableClippedObject::clip( void )
 {
+  setClipBox();
+  if ( m_bXClippingEnable )
+  {
+    getClippedObjBridge()->clipX();
+  }
+
+  if ( m_bYClippingEnable )
+  {
+    getClippedObjBridge()->clipY();
+  }
+
+  if ( m_bZClippingEnable )
+  {
+    getClippedObjBridge()->clipZ();
+  }
   m_bIsClipped = true ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableClippedObject::unClip( void )
 {
-  m_bIsClipped = false ;
+  if ( m_bIsClipped )
+  {
+    getClippedObjBridge()->unClip();
+    m_bIsClipped = false ;
+  }
+}
+/*------------------------------------------------------------------------------------------*/
+DrawableClippedObjectBridge * DrawableClippedObject::getClippedObjBridge( void )
+{
+  return dynamic_cast<DrawableClippedObjectBridge *>(m_pImp) ;
 }
 /*------------------------------------------------------------------------------------------*/
 
index 7931831..f69654a 100644 (file)
@@ -2,24 +2,20 @@
 /* file: DrawableClippedObject.h                                          */
 /* Copyright INRIA 2007                                                   */
 /* Authors : Jean-Baptiste Silvy                                          */
-/* desc : Class wich represent an object wich can be clipped              */
+/* desc : Class which represent an object which can be clipped            */
 /*------------------------------------------------------------------------*/
 
 #ifndef _DRAWABLE_CLIPPED_OBJECT_H_
 #define _DRAWABLE_CLIPPED_OBJECT_H_
 
-extern "C"
-{
-#include "../../../graphics/includes/ObjectStructure.h"
-}
-
+#include "DrawableClippedObjectBridge.h"
 #include "DrawableObject.h"
 
 namespace sciGraphics
 {
 
 /**
- * Object dedicated to render a sciPointObj.
+ * Object dedicated to render a sciPointObj with clipping.
  */
 class DrawableClippedObject : public DrawableObject
 {
@@ -35,6 +31,11 @@ public:
   bool isClipped( void ) { return m_bIsClipped ; }
 
   /**
+   * Automatically set the clipping of an object.
+   */
+  void setClipBox( void ) ;
+
+  /**
    * Set the clipping zone of the object.
    * Warning, be sure that min bounds are lower than max bounds.
    */
@@ -45,27 +46,32 @@ public:
   /**
    * Actually clip the object
    */
-  virtual void clip( void ) ;
+  void clip( void ) ;
 
   /**
-   * remove clipping. Should be called at the end of the object drawing.
+   * Remove clipping. Should be called at the end of the object drawing.
    * Otherwise it may have effect on other objects.
    */
-  virtual void unClip( void ) ;
+  void unClip( void ) ;
   
+  /**
+   * Get the bridge object
+   */
+  DrawableClippedObjectBridge * getClippedObjBridge( void ) ;
 
 protected:
 
-  double m_dXmin ;
-  double m_dXmax ;
+  /** To know if clipping is active */
+  bool m_bIsClipped ;
 
-  double m_dYmin ;
-  double m_dYmax ;
+  /** To know if clipping along X axis is enable */
+  bool m_bXClippingEnable;
 
-  double m_dZmin ;
-  double m_dZmax ;
+  /** To know if clipping along Y axis is enable */
+  bool m_bYClippingEnable;
 
-  bool m_bIsClipped ;
+  /** To know if clipping along Z axis is enable */
+  bool m_bZClippingEnable;
 
 } ;
 
diff --git a/scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.cpp b/scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.cpp
new file mode 100644 (file)
index 0000000..3ecbf47
--- /dev/null
@@ -0,0 +1,24 @@
+/*------------------------------------------------------------------------*/
+/* file: DrawableClippedObjectBridge.cpp                                  */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Class with driver dependent algorithms of DrawableClippedObject */
+/*        class                                                           */
+/*------------------------------------------------------------------------*/
+
+
+#include "DrawableClippedObjectBridge.h"
+#include "DrawableClippedObject.h"
+
+namespace sciGraphics
+{
+
+/*------------------------------------------------------------------------------------------*/
+DrawableClippedObject * DrawableClippedObjectBridge::getClippedObjectDrawer( void )
+{
+  return dynamic_cast<DrawableClippedObject *>(m_pDrawer);
+}
+/*------------------------------------------------------------------------------------------*/
+
+}
+
diff --git a/scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.h b/scilab/modules/renderer/src/cpp/DrawableClippedObjectBridge.h
new file mode 100644 (file)
index 0000000..47d2f1a
--- /dev/null
@@ -0,0 +1,66 @@
+/*------------------------------------------------------------------------*/
+/* file: DrawableClippedObjectBridge.h                                    */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Class with driver dependent algorithms of DrawableClippedObject */
+/*        class                                                           */
+/*------------------------------------------------------------------------*/
+
+#ifndef _DRAWABLE_CLIPPED_OBJECT_BRIDGE_H_
+#define _DRAWABLE_CLIPPED_OBJECT_BRIDGE_H_
+
+#include "DrawableObject.h"
+#include "DrawableObjectImp.h"
+
+namespace sciGraphics
+{
+
+class DrawableClippedObject;
+
+class DrawableClippedObjectBridge : public virtual DrawableObjectImp
+{
+public:
+
+  DrawableClippedObjectBridge( void ) {}
+
+  virtual ~DrawableClippedObjectBridge( void ) {}
+
+  /**
+   * Set the clipping zone of the object.
+   * Warning, be sure that min bounds are lower than max bounds.
+   */
+  virtual void setClipBox( double xMin, double xMax,
+                           double yMin, double yMax,
+                           double zMin, double zMax ) = 0 ;
+
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipX( void ) = 0 ;
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipY( void ) = 0 ;
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipZ( void ) = 0 ;
+
+  /**
+   * Remove clipping. Should be called at the end of the object drawing.
+   * Otherwise it may have effect on other objects.
+   */
+  virtual void unClip( void ) = 0 ;
+
+  /**
+   * Return the drawed object
+   */
+  virtual DrawableClippedObject * getClippedObjectDrawer( void ) = 0 ;
+
+protected:
+
+};
+
+}
+
+#endif /* _DRAWABLE_CLIPPED_OBJECT_BRIDGE_H_ */
diff --git a/scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.cpp b/scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.cpp
new file mode 100644 (file)
index 0000000..5d1a5cd
--- /dev/null
@@ -0,0 +1,75 @@
+/*------------------------------------------------------------------------*/
+/* file: DrawableClippedObjectJoGL.h                                      */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Class with driver dependent algorithms of DrawableClippedObject */
+/*        class using JoGL                                                */
+/*------------------------------------------------------------------------*/
+
+#include "DrawableClippedObjectJoGL.h"
+#include "DrawableObjectImp.h"
+
+extern "C"
+{
+#include "JniUtils.h"
+}
+
+
+namespace sciGraphics
+{
+
+/*------------------------------------------------------------------------------------------*/
+DrawableClippedObjectJoGL::DrawableClippedObjectJoGL( DrawableObject * drawer, const char * className )
+  : DrawableObjectJoGL(drawer, className)
+{
+  m_dXmin = 0.0;
+  m_dXmax = 0.0;
+
+  m_dYmin = 0.0;
+  m_dYmax = 0.0;
+
+  m_dZmin = 0.0;
+  m_dZmax = 0.0;
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObjectJoGL::setClipBox( double xMin, double xMax,
+                                             double yMin, double yMax,
+                                             double zMin, double zMax )
+{
+  m_dXmin = xMin;
+  m_dXmax = xMax;
+
+  m_dYmin = yMin;
+  m_dYmax = yMax;
+
+  m_dZmin = zMin;
+  m_dZmax = zMax;
+
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObjectJoGL::clipX( void )
+{
+  jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "clipX", "(DD)V", m_dXmin, m_dXmax) ;
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObjectJoGL::clipY( void )
+{
+  jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "clipY", "(DD)V", m_dYmin, m_dYmax) ;
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObjectJoGL::clipZ( void )
+{
+  jniCallMemberFunctionSafe(m_oDrawableObject, NULL, "clipZ", "(DD)V", m_dZmin, m_dZmax) ;
+}
+/*------------------------------------------------------------------------------------------*/
+void DrawableClippedObjectJoGL::unClip( void )
+{
+  jniCallMemberFunctionSafe(m_oDrawableObject,NULL,"unClip","()V");
+}
+/*------------------------------------------------------------------------------------------*/
+DrawableClippedObject * DrawableClippedObjectJoGL::getClippedObjectDrawer( void )
+{
+  return dynamic_cast<DrawableClippedObject *>(getDrawer()) ;
+}
+/*------------------------------------------------------------------------------------------*/
+}
\ No newline at end of file
diff --git a/scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.h b/scilab/modules/renderer/src/cpp/DrawableClippedObjectJoGL.h
new file mode 100644 (file)
index 0000000..9ed1079
--- /dev/null
@@ -0,0 +1,76 @@
+/*------------------------------------------------------------------------*/
+/* file: DrawableClippedObjectJoGL.h                                      */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Class with driver dependent algorithms of DrawableClippedObject */
+/*        class using JoGL                                                */
+/*------------------------------------------------------------------------*/
+
+#ifndef _DRAWABLE_CLIPPED_OBJECT_JOGL_H_
+#define _DRAWABLE_CLIPPED_OBJECT_JOGL_H_
+
+#include "DrawableClippedObjectBridge.h"
+#include "DrawableClippedObject.h"
+#include "DrawableObjectJoGL.h"
+
+namespace sciGraphics
+{
+
+class DrawableClippedObjectJoGL : public virtual DrawableClippedObjectBridge, public DrawableObjectJoGL
+{
+
+public:
+
+  DrawableClippedObjectJoGL( DrawableObject * drawer, const char * className ) ;
+
+  virtual ~DrawableClippedObjectJoGL( void ) {}
+
+
+  /**
+   * Set the clipping zone of the object.
+   * Warning, be sure that min bounds are lower than max bounds.
+   */
+  virtual void setClipBox( double xMin, double xMax,
+                           double yMin, double yMax,
+                           double zMin, double zMax ) ;
+
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipX( void ) ;
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipY( void ) ;
+  /**
+   * Actually clip the object along each axis
+   */
+  virtual void clipZ( void ) ;
+
+  /**
+   * Remove clipping. Should be called at the end of the object drawing.
+   * Otherwise it may have effect on other objects.
+   */
+  virtual void unClip( void ) ;
+
+  /**
+   * Return the drawed object
+   */
+  virtual DrawableClippedObject * getClippedObjectDrawer( void ) ;
+
+protected:
+
+  double m_dXmin ;
+  double m_dXmax ;
+
+  double m_dYmin ;
+  double m_dYmax ;
+
+  double m_dZmin ;
+  double m_dZmax ;
+
+};
+
+}
+
+#endif /* _DRAWABLE_CLIPPED_OBJECT_JOGL_H_ */
index 25b2012..796b1f1 100644 (file)
@@ -2,12 +2,18 @@
 /* file: DrawableObjectImp.h                                              */
 /* Copyright INRIA 2007                                                   */
 /* Authors : Jean-Baptiste Silvy                                          */
-/* desc : Parent class for routine independent algorithms                 */
+/* desc : Parent interface for routine independent algorithms             */
 /*------------------------------------------------------------------------*/
 
 #ifndef _DRAWABLE_OBJECT_IMP_
 #define _DRAWABLE_OBJECT_IMP_
 
+
+extern "C"
+{
+#include "MALLOC.h"
+};
+
 namespace sciGraphics
 {
 
@@ -19,15 +25,19 @@ namespace sciGraphics
 
     /**
      * Default constructor
+     * Should not take any parameter to ease multiple inheritance
      */
-    DrawableObjectImp( DrawableObject * drawer ) { m_pDrawer = drawer ; }
+    DrawableObjectImp( void ) {}
 
+    /**
+     * Destructor should not take any parameter
+     */
     virtual ~DrawableObjectImp( void ) {}
 
     /**
-    * Initialize the context for drawing (incl starting recording display list)
-    * @param figureIndex index of parentFigure
-    */
+     * Initialize the context for drawing (incl starting recording display list)
+     * @param figureIndex index of parentFigure
+     */
     virtual void initializeDrawing( void ) = 0 ;
 
     /**
@@ -51,9 +61,12 @@ namespace sciGraphics
      */
     virtual void show( void ) = 0 ;
 
-  protected:
+    /**
+     * To retrieve drawable object properties
+     */
+    virtual DrawableObject * getDrawer( void ) = 0;
 
-    DrawableObject * m_pDrawer ; /**< bridge for driver dependent algorithm */
+  protected:
 
   };
 }
index 2cb229c..fc73524 100644 (file)
@@ -16,12 +16,13 @@ extern "C"
 namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
-DrawableObjectJoGL::DrawableObjectJoGL( DrawableObject * drawer, const char * className ) : DrawableObjectImp(drawer)
+DrawableObjectJoGL::DrawableObjectJoGL( DrawableObject * drawer, const char * className )
 {
   m_oDrawableClass  = NULL ;
   m_oDrawableObject = NULL ;
+  m_pDrawer = drawer ;
   jniCreateDefaultInstanceSafe( className, &m_oDrawableClass, &m_oDrawableObject ) ;
-  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "setFigureIndex", "(I)V", sciGetNum(sciGetParentFigure(m_pDrawer->getDrawedObject())) ) ;
+  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "setFigureIndex", "(I)V", sciGetNum(sciGetParentFigure(getDrawer()->getDrawedObject())) ) ;
 }
 /*------------------------------------------------------------------------------------------*/
 DrawableObjectJoGL::~DrawableObjectJoGL( void )
@@ -31,7 +32,7 @@ DrawableObjectJoGL::~DrawableObjectJoGL( void )
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::initializeDrawing( void )
 {
-  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "initializeDrawing", "(I)V", sciGetNum(sciGetParentFigure(m_pDrawer->getDrawedObject())) ) ;
+  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "initializeDrawing", "(I)V", sciGetNum(sciGetParentFigure(getDrawer()->getDrawedObject())) ) ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::endDrawing( void )
@@ -41,7 +42,7 @@ void DrawableObjectJoGL::endDrawing( void )
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::initializeShowing( void )
 {
-  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "initializeShowing", "(I)V", sciGetNum(sciGetParentFigure(m_pDrawer->getDrawedObject())) ) ;
+  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "initializeShowing", "(I)V", sciGetNum(sciGetParentFigure(getDrawer()->getDrawedObject())) ) ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::endShowing( void )
@@ -51,14 +52,14 @@ void DrawableObjectJoGL::endShowing( void )
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::show( void )
 {
-  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "show", "(I)V", sciGetNum(sciGetParentFigure(m_pDrawer->getDrawedObject())) ) ;
+  jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "show", "(I)V", sciGetNum(sciGetParentFigure(getDrawer()->getDrawedObject())) ) ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableObjectJoGL::destroy( void )
 {
   if ( m_oDrawableObject != NULL )
   {
-    jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "destroy", "(I)V", sciGetNum(sciGetParentFigure(m_pDrawer->getDrawedObject())) ) ;
+    jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "destroy", "(I)V", sciGetNum(sciGetParentFigure(getDrawer()->getDrawedObject())) ) ;
     jniDeleteGlobalEntity(m_oDrawableObject) ;
     jniDeleteGlobalEntity(m_oDrawableClass) ;
   }
index 09cf1e5..1de1f49 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <jni.h>
 #include "DrawableObjectImp.h"
+#include "DrawableObject.h"
 
 namespace sciGraphics
 {
@@ -53,6 +54,11 @@ namespace sciGraphics
      */
     virtual void show( void ) ;
 
+    /**
+     * To retrieve the data from the drawer, specially the sciPointObj/
+     */
+    virtual DrawableObject * getDrawer( void ) { return m_pDrawer ; }
+
   protected:
     
     /*-----------------------------------------------------------------------------*/
@@ -68,6 +74,9 @@ namespace sciGraphics
     /** the instance of the Java class */
     jobject m_oDrawableObject ;
     /*-----------------------------------------------------------------------------*/
+    /** To retrieve the data from the drawer */
+    DrawableObject * m_pDrawer;
+    /*-----------------------------------------------------------------------------*/
 
   };
 }
index 451d50d..a013353 100644 (file)
 namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
-DrawableFigureImp::DrawableFigureImp( DrawableFigure * drawer ) : DrawableObjectImp( drawer )
-{
-
-}
-/*------------------------------------------------------------------------------------------*/
 DrawableFigure * DrawableFigureImp::getDrawer( void )
 {
   return dynamic_cast<DrawableFigure *>(m_pDrawer) ;
index 23fb764..0464d54 100644 (file)
@@ -22,7 +22,7 @@ class DrawableFigureImp : public virtual DrawableObjectImp
 
 public:
 
-  DrawableFigureImp( DrawableFigure * drawer ) ;
+  DrawableFigureImp( void ) {}
 
   virtual ~DrawableFigureImp( void ) {}
 
@@ -97,7 +97,7 @@ public:
   /**
    * Return the drawed object
    */
-  DrawableFigure * getDrawer( void ) ;
+  virtual DrawableFigure * getFigureDrawer( void ) = 0 ;
 
 protected:
 
index 75efb19..980a024 100644 (file)
@@ -27,12 +27,14 @@ namespace sciGraphics
 
 /*------------------------------------------------------------------------------------------*/
 DrawableFigureJoGL::DrawableFigureJoGL( DrawableFigure * drawer )
-  : DrawableObjectImp(drawer), DrawableFigureImp(drawer), DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/figureDrawing/DrawableFigureJoGL") {}
+  : DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/figureDrawing/DrawableFigureJoGL")
+{
+  
+}
 /*------------------------------------------------------------------------------------------*/
 DrawableFigureJoGL::~DrawableFigureJoGL( void )
 {
   closeRenderingCanvas() ;
-  destroy() ;
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableFigureJoGL::drawCanvas( void )
@@ -137,4 +139,9 @@ void DrawableFigureJoGL::setInfoMessage( const char * message )
   jniDeleteLocalEntity( infoMessage ) ;
 }
 /*------------------------------------------------------------------------------------------*/
+DrawableFigure * DrawableFigureJoGL::getFigureDrawer( void )
+{
+  return dynamic_cast<DrawableFigure *>(getDrawer()) ;
+}
+/*------------------------------------------------------------------------------------------*/
 }
index 40d5fa1..f702669 100644 (file)
@@ -16,7 +16,7 @@
 namespace sciGraphics
 {
 
-class DrawableFigureJoGL : public DrawableFigureImp, public DrawableObjectJoGL
+class DrawableFigureJoGL : public virtual DrawableFigureImp, public DrawableObjectJoGL
 {
 
 public:
@@ -93,6 +93,14 @@ public:
    */
   virtual void setInfoMessage( const char * message ) ;
 
+  /**
+   * Return the drawn object
+   */
+  virtual DrawableFigure * getFigureDrawer( void ) ;
+
+protected:
+
+
 } ;
 
 }
index 7ec0f25..c8c3b68 100644 (file)
@@ -13,7 +13,7 @@ namespace sciGraphics
 {
 
 /*------------------------------------------------------------------------------------------*/
-DrawablePolylineBridge::DrawablePolylineBridge( DrawablePolyline * drawer ) : DrawableObjectImp( drawer )
+DrawablePolylineBridge::DrawablePolylineBridge( DrawablePolyline * drawer )
 {
 
 }
index 53f09c6..da64ff1 100644 (file)
@@ -10,7 +10,7 @@
 #define _DRAWABLE_POLYLINE_BRIDGE_
 
 #include "../DrawableObject.h"
-#include "../DrawableObjectImp.h"
+#include "../DrawableClippedObjectBridge.h"
 
 namespace sciGraphics
 {
@@ -22,14 +22,14 @@ class DrawablePolylineBridge : public virtual DrawableObjectImp
 {
 public:
 
-  DrawablePolylineBridge( DrawablePolyline * drawer ) ;
+  DrawablePolylineBridge( void ) {}
 
-  virtual ~DrawablePolylineBridge( void ) ;
+  virtual ~DrawablePolylineBridge( void ) {}
 
   /**
-   * Return the drawed object
+   * Return the drawn object
    */
-  DrawablePolyline * getDrawer( void ) ;
+  virtual DrawablePolyline * getPolylineDrawer( void ) = 0 ;
 
 };
 
index 9d60b2a..10829e8 100644 (file)
@@ -19,14 +19,19 @@ namespace sciGraphics
 
 /*------------------------------------------------------------------------------------------*/
 DrawablePolylineJoGL::DrawablePolylineJoGL( DrawablePolyline * drawer )
-: DrawableObjectImp(drawer), DrawablePolylineBridge(drawer), DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/polylineDrawing/DrawablePolylineJoGL")
+: DrawableClippedObjectJoGL(drawer, "org/scilab/modules/renderer/polylineDrawing/DrawablePolylineJoGL")
 {
-
+  
 }
 /*------------------------------------------------------------------------------------------*/
 DrawablePolylineJoGL::~DrawablePolylineJoGL( void )
 {
-
+  
+}
+/*------------------------------------------------------------------------------------------*/
+DrawablePolyline * DrawablePolylineJoGL::getPolylineDrawer( void )
+{
+  return dynamic_cast<DrawablePolyline *>(getDrawer()) ;
 }
 /*------------------------------------------------------------------------------------------*/
 
index 54b72f9..67f0f57 100644 (file)
@@ -7,12 +7,13 @@
 /*------------------------------------------------------------------------*/
 
 #include "DrawablePolylineBridge.h"
-#include "../DrawableObjectJoGL.h"
+#include "DrawablePolyline.h"
+#include "../DrawableClippedObjectJoGL.h"
 
 namespace sciGraphics
 {
 
-class DrawablePolylineJoGL : public DrawablePolylineBridge, public DrawableObjectJoGL
+class DrawablePolylineJoGL : public DrawablePolylineBridge, public DrawableClippedObjectJoGL
 {
 
 public:
@@ -20,6 +21,13 @@ public:
 
   virtual ~DrawablePolylineJoGL( void ) ;
 
+  /**
+   * Return the drawn object
+   */
+  virtual DrawablePolyline * getPolylineDrawer( void ) ;
+
+protected:
+
 };
 
 }
index 59dc36c..423fc97 100644 (file)
@@ -6,10 +6,7 @@
 /*------------------------------------------------------------------------*/
 
 #include "DrawableRectangle.h"
-extern "C"
-{
-#include "drawRectangleEntity.h"
-}
+
 
 namespace sciGraphics
 {
@@ -19,7 +16,7 @@ using namespace std;
 /*------------------------------------------------------------------------------------------*/
 DrawableRectangle::~DrawableRectangle( void )
 {
-  
+
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableRectangle::draw( void )
@@ -31,14 +28,17 @@ void DrawableRectangle::draw( void )
     endDrawing();
     return ;
   }
-  
+  clip();
   drawRectangle() ;
+  unClip();
   endDrawing();
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableRectangle::show( void )
 {
+  clip();
   getRectangleImp()->show() ;
+  unClip();
 }
 /*------------------------------------------------------------------------------------------*/
 DrawableRectangleImp * DrawableRectangle::getRectangleImp( void )
index ff8f180..1b84328 100644 (file)
@@ -16,7 +16,7 @@ namespace sciGraphics
 using namespace std ;
 
 /*------------------------------------------------------------------------------------------*/
-DrawableRectangleImp::DrawableRectangleImp( DrawableRectangle * drawer ) : DrawableObjectImp( drawer )
+DrawableRectangleImp::DrawableRectangleImp( void )
 {
   m_oDrawingStrategies.clear() ;
 }
@@ -27,11 +27,6 @@ DrawableRectangleImp::~DrawableRectangleImp( void )
   removeDrawingStrategies() ;
 }
 /*------------------------------------------------------------------------------------------*/
-DrawableRectangle * DrawableRectangleImp::getDrawer( void )
-{
-  return dynamic_cast<DrawableRectangle *>(m_pDrawer) ;
-}
-/*------------------------------------------------------------------------------------------*/
 void DrawableRectangleImp::drawRectangle( void )
 {
   list<DrawRectangleStrategy *>::iterator it = m_oDrawingStrategies.begin() ;
index dc7288e..bad6a02 100644 (file)
@@ -10,7 +10,7 @@
 #define _DRAWABLE_RECTANGLE_IMP_H_
 
 #include "../DrawableObject.h"
-#include "../DrawableObjectImp.h"
+#include "../DrawableClippedObjectBridge.h"
 #include "DrawRectangleStrategy.h"
 #include <list>
 
@@ -22,12 +22,12 @@ namespace sciGraphics
   */
   class DrawableRectangle ;
 
-  class DrawableRectangleImp : public virtual DrawableObjectImp
+  class DrawableRectangleImp : public virtual DrawableClippedObjectBridge
   {
 
   public:
 
-    DrawableRectangleImp( DrawableRectangle * drawer ) ;
+    DrawableRectangleImp( void ) ;
 
     virtual ~DrawableRectangleImp( void ) ;
 
@@ -37,11 +37,6 @@ namespace sciGraphics
     virtual void drawRectangle( void ) ;
 
     /**
-     * Return the drawed object
-     */
-    DrawableRectangle * getDrawer( void ) ;
-
-    /**
      * Add a rendering algorithm
      */
     void addDrawingStrategy( DrawRectangleStrategy * strategy ) ;
@@ -51,11 +46,17 @@ namespace sciGraphics
      */
     void removeDrawingStrategies( void ) ;
 
+    /**
+     * Return the drawn object
+     */
+    virtual DrawableRectangle * getRectangleDrawer( void ) = 0 ;
+
   protected:
 
+
     /**
-    * List of different rendering algorithms to perform
-    */
+     * List of different rendering algorithms to perform
+     */
     std::list<DrawRectangleStrategy *> m_oDrawingStrategies ;
 
   } ;
index af4cd84..7719cdb 100644 (file)
@@ -21,19 +21,14 @@ namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
 DrawableRectangleJoGL::DrawableRectangleJoGL( DrawableRectangle * drawer )
-  : DrawableObjectImp(drawer), DrawableRectangleImp(drawer), DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/rectangleDrawing/DrawableRectangleJoGL")
+  : DrawableClippedObjectJoGL(drawer, "org/scilab/modules/renderer/rectangleDrawing/DrawableRectangleJoGL")
 {
 
 }
 /*------------------------------------------------------------------------------------------*/
 DrawableRectangleJoGL::~DrawableRectangleJoGL( void )
 {
-  destroyRectangle() ;
-}
-/*------------------------------------------------------------------------------------------*/
-void DrawableRectangleJoGL::drawRectangle( void )
-{
-  DrawableRectangleImp::drawRectangle();
+
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableRectangleJoGL::show( void )
@@ -50,4 +45,10 @@ void DrawableRectangleJoGL::destroyRectangle( void )
   DrawableObjectJoGL::destroy() ;
 }
 /*------------------------------------------------------------------------------------------*/
+DrawableRectangle * DrawableRectangleJoGL::getRectangleDrawer( void )
+{
+  return dynamic_cast<DrawableRectangle *>(getDrawer()) ;
+}
+/*------------------------------------------------------------------------------------------*/
+
 }
index bc1ce74..565069d 100644 (file)
 
 
 #include "DrawableRectangleImp.h"
-#include "../DrawableObjectJoGL.h"
+#include "DrawableRectangle.h"
+#include "../DrawableClippedObjectJoGL.h"
 
 namespace sciGraphics
 {
 
-class DrawableRectangleJoGL : public DrawableRectangleImp, public DrawableObjectJoGL
+class DrawableRectangleJoGL : public DrawableRectangleImp, public DrawableClippedObjectJoGL
 {
 
 public:
@@ -26,14 +27,15 @@ public:
   virtual ~DrawableRectangleJoGL( void ) ;
 
   /**
-   * Tell the canvas to draw itself.
+   * Call the display list of an object
    */
-  virtual void drawRectangle( void ) ;
+  virtual void show( void ) ;
 
   /**
-   * Call the display list of an object
+   * Return the drawn object
    */
-  virtual void show( void ) ;
+  DrawableRectangle * getRectangleDrawer( void ) ;
+
 
 protected:
 
index d89fd5e..e511aeb 100644 (file)
@@ -17,15 +17,15 @@ namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
 RectangleFillDrawerJoGL::RectangleFillDrawerJoGL( DrawableRectangleImp * drawer )
-  : DrawableObjectImp(drawer->getDrawer()), DrawRectangleStrategy( drawer ),
-    DrawableObjectJoGL( drawer->getDrawer(), "org/scilab/modules/renderer/rectangleDrawing/RectangleFillDrawerJoGL" )
+  : DrawRectangleStrategy( drawer ),
+    DrawableObjectJoGL(drawer->getRectangleDrawer(),"org/scilab/modules/renderer/rectangleDrawing/RectangleFillDrawerJoGL" )
 {
 
 }
 /*------------------------------------------------------------------------------------------*/
 void RectangleFillDrawerJoGL::drawRectangle( void )
 {
-  sciPointObj * pObj = m_pDrawed->getDrawer()->getDrawedObject() ;
+  sciPointObj * pObj = m_pDrawed->getRectangleDrawer()->getDrawedObject() ;
   initializeDrawing() ;
 
   // set the line parameters
@@ -37,7 +37,7 @@ void RectangleFillDrawerJoGL::drawRectangle( void )
   double corner3[3] ;
   double corner4[3] ;
 
-  m_pDrawed->getDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
+  m_pDrawed->getRectangleDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
 
   // display the rectangle
   jniCallMemberFunctionSafe( m_oDrawableObject, NULL, "drawRectangle", "(DDDDDDDDDDDD)V",
index a4f27f1..dbe43bc 100644 (file)
@@ -18,15 +18,15 @@ namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
 RectangleLineDrawerJoGL::RectangleLineDrawerJoGL( DrawableRectangleImp * drawer )
-  : DrawableObjectImp(drawer->getDrawer()), DrawRectangleStrategy( drawer ),
-    DrawableObjectJoGL( drawer->getDrawer(), "org/scilab/modules/renderer/rectangleDrawing/RectangleLineDrawerJoGL" )
+  : DrawRectangleStrategy( drawer ),
+    DrawableObjectJoGL(drawer->getRectangleDrawer(), "org/scilab/modules/renderer/rectangleDrawing/RectangleLineDrawerJoGL" )
 {
 
 }
 /*------------------------------------------------------------------------------------------*/
 void RectangleLineDrawerJoGL::drawRectangle( void )
 {
-  sciPointObj * pObj = m_pDrawed->getDrawer()->getDrawedObject() ;
+  sciPointObj * pObj = m_pDrawed->getRectangleDrawer()->getDrawedObject() ;
   initializeDrawing() ;
 
   // set the line parameters
@@ -39,7 +39,7 @@ void RectangleLineDrawerJoGL::drawRectangle( void )
   double corner3[3] ;
   double corner4[3] ;
   
-  m_pDrawed->getDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
+  m_pDrawed->getRectangleDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
 
   // display the rectangle
 
index 167e1bb..c59ca6c 100644 (file)
@@ -20,6 +20,8 @@ namespace sciGraphics
 
     RectangleLineDrawerJoGL( DrawableRectangleImp * drawer ) ;
 
+    virtual ~RectangleLineDrawerJoGL( void ) {}
+
     /**
      * Main algorithm to draw the outline of the rectangle
      */
@@ -30,6 +32,9 @@ namespace sciGraphics
      */
     virtual void show( void ) { DrawableObjectJoGL::show(); }
 
+  protected:
+
+
   };
 
 
index e9ff337..cffb97f 100644 (file)
@@ -18,8 +18,8 @@ namespace sciGraphics
 {
 /*------------------------------------------------------------------------------------------*/
 RectangleMarkDrawerJoGL::RectangleMarkDrawerJoGL( DrawableRectangleImp * drawer )
-  : DrawableObjectImp(drawer->getDrawer()), DrawRectangleStrategy( drawer ),
-    DrawableObjectJoGL( drawer->getDrawer(), "org/scilab/modules/renderer/rectangleDrawing/RectangleMarkDrawerJoGL" )
+  : DrawRectangleStrategy( drawer ),
+    DrawableObjectJoGL(drawer->getRectangleDrawer(), "org/scilab/modules/renderer/rectangleDrawing/RectangleMarkDrawerJoGL" )
 {
 
 }
@@ -27,7 +27,7 @@ RectangleMarkDrawerJoGL::RectangleMarkDrawerJoGL( DrawableRectangleImp * drawer
 void RectangleMarkDrawerJoGL::drawRectangle( void )
 {
 
-  sciPointObj * pObj = m_pDrawed->getDrawer()->getDrawedObject() ;
+  sciPointObj * pObj = m_pDrawed->getRectangleDrawer()->getDrawedObject() ;
   initializeDrawing() ;
 
   // set the line parameters
@@ -41,7 +41,7 @@ void RectangleMarkDrawerJoGL::drawRectangle( void )
   double corner3[3] ;
   double corner4[3] ;
 
-  m_pDrawed->getDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
+  m_pDrawed->getRectangleDrawer()->getCornersCoordinates( corner1, corner2, corner3, corner4 ) ;
 
   // display the rectangle
 
index bd25004..384472a 100644 (file)
@@ -31,11 +31,11 @@ public:
   /**
   * Set the parent subwin, needed by CameraImpFactory.
   */
-  void setCorrespondingSubwin( DrawableObject * subwin ) { m_pSubwin = subwin; }
+  void setCorrespondingSubwin( DrawableSubwin * subwin ) { m_pSubwin = subwin; }
 
 protected:
 
-  DrawableObject * m_pSubwin;
+  DrawableSubwin * m_pSubwin;
 
 };
 
index 69bc650..fbf3cc4 100644 (file)
@@ -31,11 +31,11 @@ public:
   /**
    * Set the parent subwin, needed by CameraImpFactory.
    */
-  void setCorrespondingSubwin( DrawableObject * subwin ) { m_pSubwin = subwin; }
+  void setCorrespondingSubwin( DrawableSubwin * subwin ) { m_pSubwin = subwin; }
 
 protected:
 
-  DrawableObject * m_pSubwin;
+  DrawableSubwin * m_pSubwin;
 
 };
 
index cad93ff..16c54b4 100644 (file)
@@ -17,8 +17,8 @@ namespace sciGraphics
 {
 
 /*-----------------------------------------------------------------------------------*/
-CameraJoGL::CameraJoGL( DrawableObject * subwin )
-  : DrawableObjectImp(subwin), CameraBridge(),
+CameraJoGL::CameraJoGL( DrawableSubwin * subwin )
+  : CameraBridge(),
     DrawableObjectJoGL(subwin, "org/scilab/modules/renderer/subwinDrawing/CameraJoGL")
 {
 
index aa40673..5b8898e 100644 (file)
@@ -26,7 +26,7 @@ public:
    * Default constructor
    * @param subwin Subwindow containign the camera
    */
-  CameraJoGL( DrawableObject * subwin ) ;
+  CameraJoGL( DrawableSubwin * subwin ) ;
 
   /**
    * Position the view and view area accordingly to previous calls.
index 9a50d1a..fa09169 100644 (file)
@@ -17,7 +17,7 @@ namespace sciGraphics
 {
 
 /*------------------------------------------------------------------------------------------*/
-DrawableSubwin::DrawableSubwin(sciPointObj * pObj) : DrawableClippedObject(pObj)
+DrawableSubwin::DrawableSubwin(sciPointObj * pObj) : DrawableObject(pObj)
 {
   m_pCamera = NULL ;
 }
@@ -29,6 +29,7 @@ DrawableSubwin::~DrawableSubwin( void )
     delete m_pCamera ;
   }
   m_pCamera = NULL;
+
 }
 /*------------------------------------------------------------------------------------------*/
 void DrawableSubwin::draw( void )
index 944725c..4996779 100644 (file)
@@ -9,14 +9,14 @@
 #define _DRAWABLE_SUBWIN_H_
 
 
-#include "../DrawableClippedObject.h"
+#include "../DrawableObject.h"
 #include "Camera.h"
 #include "DrawableSubwinBridge.h"
 
 namespace sciGraphics
 {
 
-class DrawableSubwin : public DrawableClippedObject
+class DrawableSubwin : public DrawableObject
 {
 
 public:
index 3f413a4..eba23dd 100644 (file)
@@ -25,17 +25,17 @@ namespace sciGraphics
 
   public:
 
-    DrawableSubwinBridge( DrawableSubwin * drawer ) ;
+    DrawableSubwinBridge( void ) {}
 
     virtual ~DrawableSubwinBridge( void ) {}
 
+
+  protected:
+
     /**
      * Return the drawed object
      */
-    DrawableSubwin * getDrawer( void ) ;
-
-
-  protected:
+    virtual DrawableSubwin * getSubwinDrawer( void ) = 0 ;
 
   } ;
 
index cc50ab7..5221c37 100644 (file)
@@ -22,15 +22,19 @@ namespace sciGraphics
 
 /*------------------------------------------------------------------------------------------*/
 DrawableSubwinJoGL::DrawableSubwinJoGL( DrawableSubwin * drawer )
-  : DrawableObjectImp(drawer), DrawableSubwinBridge(drawer),
-    DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/subwinDrawing/DrawableSubwinJoGL")
+  : DrawableObjectJoGL(drawer, "org/scilab/modules/renderer/subwinDrawing/DrawableSubwinJoGL")
 {
 
 }
 /*------------------------------------------------------------------------------------------*/
 DrawableSubwinJoGL::~DrawableSubwinJoGL( void )
 {
-  //destroy() ;
+
+}
+/*------------------------------------------------------------------------------------------*/
+DrawableSubwin * DrawableSubwinJoGL::getSubwinDrawer( void )
+{
+  return dynamic_cast<DrawableSubwin *>(getDrawer()) ;
 }
 /*------------------------------------------------------------------------------------------*/
 
index 721a680..ad4d807 100644 (file)
 #define _DRAWABLE_SUBWIN_JOGL_H_
 
 #include "DrawableSubwinBridge.h"
-//#include "DrawableSubwin.h"
+#include "DrawableSubwin.h"
 #include "../DrawableObjectJoGL.h"
 
 namespace sciGraphics
 {
 
-  class DrawableSubwinJoGL : public DrawableSubwinBridge, public DrawableObjectJoGL
+  class DrawableSubwinJoGL : public virtual DrawableSubwinBridge, public DrawableObjectJoGL
   {
 
   public:
@@ -25,6 +25,15 @@ namespace sciGraphics
 
     virtual ~DrawableSubwinJoGL( void ) ;
 
+    /**
+     * Return the drawn object
+     */
+    virtual DrawableSubwin * getSubwinDrawer( void ) ;
+
+  protected:
+
+    DrawableSubwin * m_pDrawed ;
+
   } ;
 
 }
index 012f217..5c96d46 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.scilab.modules.renderer;
 
-import org.scilab.modules.renderer.utils.GLTools;
+import org.scilab.modules.renderer.utils.glTools.GLTools;
 
 /**
  * Class which can be automatically shown.
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/DrawableClippedObjectJoGL.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/DrawableClippedObjectJoGL.java
new file mode 100644 (file)
index 0000000..74d8c5d
--- /dev/null
@@ -0,0 +1,91 @@
+/*------------------------------------------------------------------------*/
+/* file: DrawableClippedObjectJoGL.java                                   */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Parent class to render clipped objects                          */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer;
+import javax.media.opengl.GL;
+
+import org.scilab.modules.renderer.utils.glTools.MovableClipPlane3D;
+
+/**
+ * Parent class to render clipped objects
+ * @author Jean-Baptiste Silvy
+ */
+public abstract class DrawableClippedObjectJoGL extends DrawableObjectJoGL {
+
+       private MovableClipPlane3D planeXmin;
+       private MovableClipPlane3D planeXmax;
+       private MovableClipPlane3D planeYmin;
+       private MovableClipPlane3D planeYmax;
+       private MovableClipPlane3D planeZmin;
+       private MovableClipPlane3D planeZmax;
+
+       /**
+        * Clip an object with 2 planes, along X axis
+        * @param xMin minimum shown value on X axis
+        * @param xMax maximum shown value on X axis
+        */
+       public void clipX(double xMin, double xMax) {
+               GL gl = getGL();
+               // drawn points (x,y,z) are the one verifying a.x + b.y + c.z + d >= 0.
+               double[] equationXmin = {1.0, 0.0, 0.0, -xMin}; // x >= xMin
+               planeXmin = new MovableClipPlane3D(equationXmin);
+               planeXmin.clip(gl);
+
+               double[] equationXmax = {-1.0, 0.0, 0.0, xMax}; // x <= xMax
+               planeXmax = new MovableClipPlane3D(equationXmax);
+               planeXmax.clip(gl);
+               
+       }
+       
+       /**
+        * Clip an object with 2 planes, along Y axis
+        * @param yMin minimum shown value on Y axis
+        * @param yMax maximum shown value on Y axis
+        */
+       public void clipY(double yMin, double yMax) {
+               GL gl = getGL();
+               double[] equationYmin = {0.0, 1.0, 0.0, -yMin};
+               planeYmin = new MovableClipPlane3D(equationYmin);
+               planeYmin.clip(gl);
+
+               double[] equationYmax = {0.0, -1.0, 0.0, yMax};
+               planeYmax = new MovableClipPlane3D(equationYmax);
+               planeYmax.clip(gl);
+       }
+       
+       /**
+        * Clip an object with 2 planes, along Z axis
+        * @param zMin minimum shown value on Z axis
+        * @param zMax maximum shown value on Z axis
+        */
+       public void clipZ(double zMin, double zMax) {
+               GL gl = getGL();
+               double[] equationZmin = {0.0, 0.0, 1.0, -zMin};
+               planeZmin = new MovableClipPlane3D(equationZmin);
+               planeZmin.clip(gl);
+
+               double[] equationZmax = {0.0, 0.0, -1.0, zMax};
+               planeZmax = new MovableClipPlane3D(equationZmax);
+               planeZmax.clip(gl);
+       }
+       
+       
+       /**
+        * Disable clipping after a call to clip
+        */
+       public void unClip() {
+               GL gl = getGL();
+               planeXmin.unClip(gl);
+               planeXmax.unClip(gl);
+               planeYmin.unClip(gl);
+               planeYmax.unClip(gl);
+               planeZmin.unClip(gl);
+               planeZmax.unClip(gl);
+       }
+
+}
index 7336cf1..c23c224 100644 (file)
@@ -8,7 +8,8 @@
 package org.scilab.modules.renderer;
 
 import javax.media.opengl.GL;
-import org.scilab.modules.renderer.utils.GLTools;
+
+import org.scilab.modules.renderer.utils.glTools.GLTools;
 
 /**
  * Parent class for all graphic classes corresponding to a cpp one
index 24702df..539a069 100644 (file)
@@ -74,6 +74,9 @@ public class DrawableFigureJoGL extends ObjectJoGL {
                destroyedObjects.destroyAll(parentFigureIndex);
                super.initializeDrawing(parentFigureIndex);
                getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+               getGL().glClearDepth(1.0f);
+               getGL().glEnable(GL.GL_DEPTH_TEST);
+               getGL().glDepthFunc(GL.GL_LEQUAL);
        }
        
        /**
@@ -194,6 +197,7 @@ public class DrawableFigureJoGL extends ObjectJoGL {
         * Called when the object is destroyed from C code
         * @param parentFigureIndex index of parent figure
         */
+       @Override
        public void destroy(int parentFigureIndex) {
                // figure should not be add to the object cleaner or will destroy themselves.
                // no operation for now
index 85f01ee..0706a97 100644 (file)
@@ -8,13 +8,13 @@
 
 package org.scilab.modules.renderer.rectangleDrawing;
 
-import org.scilab.modules.renderer.ObjectJoGL;
+import org.scilab.modules.renderer.DrawableClippedObjectJoGL;
 
 /**
  * Class containing functions called by DrawableRectangleJoGL.cpp
  * @author Jean-Baptiste Silvy
  */
-public class DrawableRectangleJoGL extends ObjectJoGL {
+public class DrawableRectangleJoGL extends DrawableClippedObjectJoGL {
 
        /**
         * Default Constructor
@@ -23,4 +23,10 @@ public class DrawableRectangleJoGL extends ObjectJoGL {
                super();
        }
        
+       /**
+        * Display the object by displaying its display list
+        * @param parentFigureIndex index of the parent figure in which the object will be drawn
+        */
+       public void show(int parentFigureIndex) { }
+       
 }
index cd94e4b..87821a7 100644 (file)
@@ -10,7 +10,8 @@ package org.scilab.modules.renderer.rectangleDrawing;
 
 import org.scilab.modules.renderer.AutoDrawableObjectJoGL;
 import javax.media.opengl.GL;
-import org.scilab.modules.renderer.utils.GLTools;
+
+import org.scilab.modules.renderer.utils.glTools.GLTools;
 
 /**
  * Class containing functions called by RectangleLineDrawerJoGL.cpp
index 5d67e23..eadb60a 100644 (file)
@@ -13,8 +13,9 @@ import org.scilab.modules.renderer.DrawableObjectJoGL;
 import javax.media.opengl.GL;
 
 import org.scilab.modules.renderer.utils.MarkDrawing.MarkDrawer;
+import org.scilab.modules.renderer.utils.geom3D.Vector3D;
+import org.scilab.modules.renderer.utils.glTools.GLTools;
 import org.scilab.modules.renderer.utils.CoordinateTransformation;
-import org.scilab.modules.renderer.utils.GLTools;
 
 /**
  * Class containing functions called by RectangleMarkDrawerJoGL.cpp
@@ -23,21 +24,20 @@ import org.scilab.modules.renderer.utils.GLTools;
 public class RectangleMarkDrawerJoGL extends DrawableObjectJoGL {
        
        private static final int NB_CORNERS = 4;
-       private static final int NB_COORDS  = 3;
        
        
        /** index of background color */
        private MarkDrawer drawer;
        
        /** position of corners, needed to retrive pixels coordinates */
-       private double[][] cornersPos;
+       private Vector3D[] cornersPos;
        
        /**
         * Default Constructor
         */
        public RectangleMarkDrawerJoGL() {
                drawer = null;
-               cornersPos = new double[NB_CORNERS][NB_COORDS];
+               cornersPos = new Vector3D[NB_CORNERS];
        }
        
        /**
@@ -139,13 +139,16 @@ public class RectangleMarkDrawerJoGL extends DrawableObjectJoGL {
                CoordinateTransformation transform = CoordinateTransformation.getTransformation();
                
                // need to perform this befaore swithching to pixel coordinates
-               double[][] pixCoords = transform.getCanvasCoordinates(gl, cornersPos);
+               Vector3D[] pixCoords = transform.getCanvasCoordinates(gl, cornersPos);
+               
                
                // switch to pixel coordinates
                GLTools.usePixelCoordinates(gl);
                
                for (int i = 0; i < NB_CORNERS; i++) {
-                       drawer.drawMark(pixCoords[i][0], pixCoords[i][1], pixCoords[i][2]);
+                       // switch back to the new frame
+                       Vector3D curCoord = transform.retrieveSceneCoordinates(gl, pixCoords[i]);
+                       drawer.drawMark(curCoord.getX(), curCoord.getY(), curCoord.getZ());
                }
                
                GLTools.endPixelCoordinates(gl);
@@ -174,18 +177,10 @@ public class RectangleMarkDrawerJoGL extends DrawableObjectJoGL {
                
                
                // save rectangle coordinates
-               cornersPos[0][0] = corner1X;
-               cornersPos[0][1] = corner1Y;
-               cornersPos[0][2] = corner1Z;
-               cornersPos[1][0] = corner2X;
-               cornersPos[1][1] = corner2Y;
-               cornersPos[1][2] = corner2Z;
-               cornersPos[2][0] = corner3X;
-               cornersPos[2][1] = corner3Y;
-               cornersPos[2][2] = corner3Z;
-               cornersPos[NB_CORNERS - 1][0] = corner4X; // To avoid javadoc warning
-               cornersPos[NB_CORNERS - 1][1] = corner4Y;
-               cornersPos[NB_CORNERS - 1][2] = corner4Z;
+               cornersPos[0] = new Vector3D(corner1X, corner1Y, corner1Z);
+               cornersPos[1] = new Vector3D(corner2X, corner2Y, corner2Z);
+               cornersPos[2] = new Vector3D(corner3X, corner3Y, corner3Z);
+               cornersPos[NB_CORNERS - 1] = new Vector3D(corner4X, corner4Y, corner4Z);
                
                drawRectangle();
                
index cc7929b..6c0e351 100644 (file)
@@ -19,7 +19,7 @@ import javax.media.opengl.GL;
 public class CameraJoGL extends ObjectJoGL {
 
        /** Distance of the far clipping plane, should be greater than 1.0 and not to high */
-       private static final double FAR_PLANE_DISTANCE = 100.0;
+       public static final double FAR_PLANE_DISTANCE = 100.0;
        
        /** Default rotation angles, 2D view */
        private static final double DEFAULT_ALPHA = 0.0;
@@ -95,8 +95,8 @@ public class CameraJoGL extends ObjectJoGL {
                // rotate around the center of the box axes
                gl.glTranslated(centerX, centerY, centerZ);
                gl.glScaled(reductionRatio, reductionRatio, reductionRatio); // reduction need to be performed on the center of the screen
-               gl.glRotated(-DEFAULT_ALPHA - alpha, 1.0 , 0.0, 0.0); /* Seems we need to rotate counterclok-wise */
-               gl.glRotated(-DEFAULT_THETA - theta, 0.0 , 0.0, 1.0);
+               gl.glRotated(DEFAULT_ALPHA - alpha, 1.0 , 0.0, 0.0); /* Seems we need to rotate counterclok-wise */
+               gl.glRotated(DEFAULT_THETA - theta, 0.0 , 0.0, 1.0);
                gl.glTranslated(-centerX, -centerY, -centerZ); // translate origin back
        }
        
index c88986d..adda0e6 100644 (file)
@@ -8,13 +8,13 @@
 
 package org.scilab.modules.renderer.subwinDrawing;
 
-import org.scilab.modules.renderer.AutoDrawableObjectJoGL;
+import org.scilab.modules.renderer.DrawableObjectJoGL;
 
 /**
  * Class containing functions called by DrawableSubwinJoGL.cpp
  * @author Jean-Baptiste Silvy
  */
-public class DrawableSubwinJoGL extends AutoDrawableObjectJoGL {
+public class DrawableSubwinJoGL extends DrawableObjectJoGL {
 
        /**
         * Default Constructor
@@ -23,4 +23,10 @@ public class DrawableSubwinJoGL extends AutoDrawableObjectJoGL {
                super();
        }
        
+       /**
+        * Display the object by displaying its display list
+        * @param parentFigureIndex index of the parent figure in which the object will be drawn
+        */
+       public void show(int parentFigureIndex) { }
+       
 }
index a1b78bd..ea19326 100644 (file)
@@ -12,6 +12,8 @@ package org.scilab.modules.renderer.utils;
 import javax.media.opengl.GL;
 import javax.media.opengl.glu.GLU;
 
+import org.scilab.modules.renderer.utils.geom3D.Vector3D;
+
 /**
  * Class containing functions to switch between user and window coordinates.
  * This is a singleton class.
@@ -20,8 +22,17 @@ import javax.media.opengl.glu.GLU;
 public class CoordinateTransformation {
 
        /** transformation matrices sizes */
-       private static final int PROJECTION_MATRIX_SIZE = 16;
-       private static final int VIEWPORT_SIZE          = 4;
+       private static final int MATRIX_4X4_SIZE = 16;
+       private static final int VIEWPORT_SIZE   = 4;
+       
+       /** Identity matrix of size 4x4 */
+       private static final double[] IDENTITY_4X4 = {1.0, 0.0, 0.0, 0.0,
+                                                                                                 0.0, 1.0, 0.0, 0.0,
+                                                                                                 0.0, 0.0, 1.0, 0.0,
+                                                                                                 0.0, 0.0, 0.0, 1.0};
+       
+       /** The six translation indices in an frame changing matrix */
+       private static final int[] TRANSLATION_INDICES = {3, 7, 11, 12, 13, 14};
        
        /** Singleton */
        private static CoordinateTransformation transform;
@@ -35,8 +46,8 @@ public class CoordinateTransformation {
         * default constructor
         */
        protected CoordinateTransformation() {
-               modelViewMatrix = new double[PROJECTION_MATRIX_SIZE];
-               projectionMatrix = new double[PROJECTION_MATRIX_SIZE];
+               modelViewMatrix = new double[MATRIX_4X4_SIZE];
+               projectionMatrix = new double[MATRIX_4X4_SIZE];
                viewPort = new int[VIEWPORT_SIZE];
        }
        
@@ -78,32 +89,18 @@ public class CoordinateTransformation {
        /**
         * Get the coordinate of a 3D position in a canvas frame from its user coordinates.
         * @param gl current OpenGL pipeline
-        * @param posX X coordinate of the position
-        * @param posY Y coordinate of the position
-        * @param posZ Z coordinate of the position
-        * @param canvasCoord Result, array of size 3 containing the X, Y and Z positions in the canavs frame.
+        * @param pos coordinates of the position (size 3).
+        * @return array of size 3 containing the X, Y and Z positions in the canvas frame.
         */
-       public void getCanvasCoordinates(GL gl, double posX, double posY, double posZ, double[] canvasCoord) {
-               // get current matrices
+       public Vector3D getCanvasCoordinates(GL gl, Vector3D pos) {
+               double[] canvasCoord = {0.0, 0.0, 0.0};
                GLU glu = new GLU();
                updateModelViewMatrix(gl);
                updateProjectionMatrix(gl);
                updateViewPort(gl);
                
-               glu.gluProject(posX, posY, posZ, modelViewMatrix, 0, projectionMatrix, 0, viewPort, 0, canvasCoord, 0);
-               
-       }
-       
-       /**
-        * Get the coordinate of a 3D position in a canvas frame from its user coordinates.
-        * @param gl current OpenGL pipeline
-        * @param pos coordinates of the position (size 3).
-        * @return array of size 3 containing the X, Y and Z positions in the canvas frame.
-        */
-       public double[] getCanvasCoordinates(GL gl, double[] pos) {
-               double[] canvasCoord = new double[pos.length];
-               getCanvasCoordinates(gl, pos[0], pos[1], pos[2], canvasCoord);
-               return canvasCoord;
+               glu.gluProject(pos.getX(), pos.getY(), pos.getZ(), modelViewMatrix, 0, projectionMatrix, 0, viewPort, 0, canvasCoord, 0);
+               return new Vector3D(canvasCoord);
        }
        
        /**
@@ -113,9 +110,9 @@ public class CoordinateTransformation {
         * @return array of size n x 3 containing the X, Y and Z positions in the canvas frame
         *                                         corresponding to each 
         */
-       public double[][] getCanvasCoordinates(GL gl, double[][] positions) {
+       public Vector3D[] getCanvasCoordinates(GL gl, Vector3D[] positions) {
                int nbCoords = positions.length;
-               double[][] canvasCoords = new double[nbCoords][];
+               Vector3D[] canvasCoords = new Vector3D[nbCoords];
                
                for (int i = 0; i < nbCoords; i++) {
                        canvasCoords[i] = getCanvasCoordinates(gl, positions[i]);
@@ -123,4 +120,25 @@ public class CoordinateTransformation {
                return canvasCoords;
        }
        
+       /**
+        * Opposite transformation od getCanvasCoordinates.
+        * Compute back scene coordinates from window coordinates.
+        * @param gl current OpengL pipeline
+        * @param canvasPos coordinates of the point in the canvas frame
+        * @return coodinates in object frame
+        */
+       public Vector3D retrieveSceneCoordinates(GL gl, Vector3D canvasPos) {
+               double[] objectPos = {0.0, 0.0, 0.0};
+               // get current matrices
+               GLU glu = new GLU();
+               updateModelViewMatrix(gl);
+               updateProjectionMatrix(gl);
+               updateViewPort(gl);
+               
+               glu.gluUnProject(canvasPos.getX(), canvasPos.getY(), canvasPos.getZ(),
+                                                modelViewMatrix, 0, projectionMatrix, 0, viewPort, 0, objectPos, 0);
+               
+               return new Vector3D(objectPos);
+       }
+       
 }
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Plane3D.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Plane3D.java
new file mode 100644 (file)
index 0000000..c27010c
--- /dev/null
@@ -0,0 +1,223 @@
+/*------------------------------------------------------------------------*/
+/* file: GLTools.java                                                     */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Represent a 3D plane with its equation A.x + B.y + C.z + D = 0  */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer.utils.geom3D;
+
+/**
+ * Represent a 3D plane with its equation A.x + B.y + C.z + D = 0
+ * @author Jean-Baptiste Silvy
+ */
+public class Plane3D {
+       
+       /** Number of parameter to describe the plane */
+       public static final int PLANE3D_EQUATION_LENGTH = 4;
+       
+       private double a;
+       private double b;
+       private double c;
+       private double d;
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param a first equation parameter
+        * @param b second equation parameter
+        * @param c third equation parameter
+        * @param d fourth equation parameter
+        */
+       public Plane3D(double a, double b, double c, double d) {
+               setEquation(a, b, c, d);
+       }
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param equation array of size 4 giving a, b, c and d
+        */
+       public Plane3D(double[] equation) {
+               setEquation(equation);
+       }
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param copyPlane the plane to copy
+        */
+       public Plane3D(Plane3D copyPlane) {
+               setEquation(copyPlane.getEquation());
+       }
+       
+       /**
+        * Define a plane by giving three of its non aligned points
+        * @param point1 first point
+        * @param point2 second point
+        * @param point3 third point
+        */
+       public Plane3D(Vector3D point1, Vector3D point2, Vector3D point3) {
+               setEquation(point1, point2, point3);
+       }
+       
+       /**
+        * Default constructor. Should not be used, it does not create a valid plane.
+        */
+       protected Plane3D() {
+               setEquation(0.0, 0.0, 0.0, 0.0);
+       }
+       
+       
+       /**
+        * Get the equation of the plane
+        * @param equation array of size 4
+        */
+       public void getEquation(double[] equation) {
+               equation[0] = a;
+               equation[1] = b;
+               equation[2] = c;
+               equation[PLANE3D_EQUATION_LENGTH - 1] = d;
+       }
+       
+       /**
+        * Get the equation of the plane
+        * @return equation which is array of size 4
+        */
+       public double[] getEquation() {
+               double[] equation = new double[PLANE3D_EQUATION_LENGTH];
+               getEquation(equation);
+               return equation;
+       }
+       
+       /**
+        * Set the equation of the plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param a first equation parameter
+        * @param b second equation parameter
+        * @param c third equation parameter
+        * @param d fourth equation parameter
+        */
+       protected void setEquation(double a, double b, double c, double d) {
+               this.a = a;
+               this.b = b;
+               this.c = c;
+               this.d = d;
+       }
+       
+       /**
+        * Set plane equation by giving the equation a.x + b.y + c.z + d = 0
+        * @param equation array of size 4 giving a, b, c and d
+        */
+       protected void setEquation(double[] equation) {
+               setEquation(equation[0], equation[1], equation[2], equation[PLANE3D_EQUATION_LENGTH - 1]);
+       }
+       
+       /**
+        * Miltuply the equation by a scalar. Does not modify the plane unless scalar is 0.
+        * @param scalar multiplication scalar. Should not be 0.
+        */
+       protected void scalarMult(double scalar) {
+               a = scalar * a;
+               b = scalar * b;
+               c = scalar * c;
+               d = scalar * d;
+       }
+       
+       /**
+        * Set plane equation by giving three of its non aligned points
+        * @param point1 first point
+        * @param point2 second point
+        * @param point3 third point
+        */
+       public void setEquation(Vector3D point1, Vector3D point2, Vector3D point3) {
+               // first compute the normal of the plane
+               Vector3D p1p2 = point2.substract(point1);
+               Vector3D p1p3 = point3.substract(point1);
+
+               Vector3D normal = p1p2.crossProduct(p1p3);
+               normal.normalize();
+               
+               setEquation(point1, normal);
+               
+       }
+       
+       /**
+        * Set plane equation by knowing its normal and a poinr on the plane
+        * @param point point on the plane
+        * @param normal normal of the plane
+        */
+       public void setEquation(Vector3D point, Vector3D normal) {
+               // equation of the plane is Nx.x + Ny.y + Nz.z + d = 0
+               this.a = normal.getX();
+               this.b = normal.getY();
+               this.c = normal.getZ();
+               
+               // point is on the plane so a.p1x + b.p1y + c.p1z + d = 0;
+               this.d = -this.a * point.getX() - this.b * point.getY() - this.c * point.getZ();
+       }
+       
+       /**
+        * get a normal of the plane
+        * @return normal of the plane
+        */
+       public Vector3D getNormal() {
+               Vector3D res = new Vector3D(a, b, c);
+               res.normalize();
+               return res;
+       }
+       
+       
+       /**
+        * Get the a point on the plane and its normal
+        * @param point a point on the plane
+        * @param normal normal of the plane, normalized
+        */
+       public void getPointAndNormal(Vector3D point, Vector3D normal) {
+               getThreePointsOnPlane(point, point, point);
+               normal.setValues(getNormal());
+       }
+       
+       /**
+        * Compute the coordinates of three points included on the plane.
+        * The tripet (P1, P1P2, P1P3) is defining an orthonormal frame.
+        * @param point1 first point
+        * @param point2 second point
+        * @param point3 third point
+        */
+       public void getThreePointsOnPlane(Vector3D point1, Vector3D point2, Vector3D point3) {
+
+               if (Math.abs(a) >= Math.abs(b) && Math.abs(a) >= Math.abs(c)) {
+                       
+                       // a is the greatest so we can use it as divider.
+                   // we assume that at least one of the first three parameters is not 0.
+                   // now we fix some value for y and z and find the corresponding x
+                   // to avoid arithmetical issues we use the values values (0,0) and (1,1)
+                   point1.setValues(-d / a, 0.0, 0.0); // A.x + 0.B + 0.C + D = 0
+                   point2.setValues(-(b + c + d) / a, 1.0, 1.0); // A.x + B + C + D = 0
+                   
+               } else if (Math.abs(b) >= Math.abs(c)) {
+                       // same with b instead of a
+                       point1.setValues(0.0, -d / b, 0.0); // 0.A + B.y + 0.C + D = 0
+                       point2.setValues(1.0, -(a + c + d) / b, 1.0); // A + B.y + C + D = 0
+                       
+               } else {
+                       // same with c
+                       point1.setValues(0.0, 0.0, -d / c); // 0.A + 0.B + C.z + D = 0
+                       point2.setValues(1.0, 1.0, -(a + b + d) / c); // A + B + C.z + D = 0
+               }
+               Vector3D p1p2 = point2.substract(point1);
+               p1p2.normalize(); // normalize distance between P1 and P2
+               point2.setValues(point1.add(p1p2)); // retrieve P2 coordinates
+               
+               // find the last vector, cross product of the normal (Z) and the first vector (X).
+               Vector3D p1p3 = getNormal().crossProduct(p1p2);
+               point3.setValues(point1.add(p1p3));
+               
+       }
+
+       /**
+        * @return text representation of the plane
+        */
+       public String toString() {
+               return a + "x + " + b + "y + " + c + ".z + " + d + " = 0";
+       }
+
+}
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Vector3D.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/geom3D/Vector3D.java
new file mode 100644 (file)
index 0000000..6ff614a
--- /dev/null
@@ -0,0 +1,209 @@
+/*------------------------------------------------------------------------*/
+/* file: GLTools.java                                                     */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Represent a 3D vector                                           */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer.utils.geom3D;
+
+
+/**
+ * Class which represent a 3D vector
+ * @author Jean-Baptiste Silvy
+ */
+public class Vector3D {
+
+       private double xCoord;
+       private double yCoord;
+       private double zCoord;
+       
+       /**
+        * Default constructor
+        */
+       public Vector3D() {
+               xCoord = 0.0;
+               yCoord = 0.0;
+               zCoord = 0.0;
+       }
+       
+       /**
+        * Copy constructor
+        * @param copy the vector which is copied
+        */
+       public Vector3D(Vector3D copy) {
+               setValues(copy);
+       }
+       
+       /**
+        * Constructor from an array
+        * @param values array with 3 values
+        */
+       public Vector3D(double[] values) {
+               setValues(values);
+       }
+       
+       /**
+        * Constructor from the 3 coordinates
+        * @param xCoord X coordinate
+        * @param yCoord Y coordinate
+        * @param zCoord Z coordinate
+        */
+       public Vector3D(double xCoord, double yCoord, double zCoord) {
+               setValues(xCoord, yCoord, zCoord);
+       }
+       
+       /**
+        * @return Vector X coordinates
+        */
+       public double getX() {
+               return xCoord;
+       }
+       
+       /**
+        * @return Vector Y coordinates
+        */
+       public double getY() {
+               return yCoord;
+       }
+       
+       /**
+        * @return Vector Z coordinates
+        */
+       public double getZ() {
+               return zCoord;
+       }
+       
+       
+       /**
+        * Set new coordinates for the vector
+        * @param x new X coordinate
+        * @param y new Y coordinate
+        * @param z new Z coordinate
+        */
+       public void setValues(double x, double y, double z) {
+               xCoord = x;
+               yCoord = y;
+               zCoord = z;
+       }
+       
+       /**
+        * Set coordinates of the vector
+        * @param values array of size 3 containing the coordinates
+        */
+       public void setValues(double[] values) {
+               xCoord = values[0];
+               yCoord = values[1];
+               zCoord = values[2];
+       }
+       
+       /**
+        * Copy a vector to this one
+        * @param copy vector to copy
+        */
+       public void setValues(Vector3D copy) {
+               xCoord = copy.xCoord;
+               yCoord = copy.yCoord;
+               zCoord = copy.zCoord;
+       }
+       
+       /**
+        * @return array of the 3 coodinates
+        */
+       public double[] getValues() {
+               double[] res = {xCoord, yCoord, zCoord};
+               return res;
+       }
+       
+       /**
+        * Return the dot product of this vector with an other
+        * @param v2 other vector
+        * @return dot prodeuct of the two vectors
+        */
+       public double dotProduct(Vector3D v2) {
+               return xCoord * v2.xCoord + yCoord * v2.yCoord + zCoord * v2.zCoord;
+       }
+       
+       /**
+        * Compute the cross product of this vector with an other
+        * @param v2 other vector
+        * @return new vector, result of the cross product
+        */
+       public Vector3D crossProduct(Vector3D v2) {
+               return new Vector3D(yCoord * v2.zCoord - zCoord * v2.yCoord,
+                                                       zCoord * v2.xCoord - xCoord * v2.zCoord,
+                                                       xCoord * v2.yCoord - yCoord * v2.xCoord);
+       }
+       
+       /**
+        * @return norm of the vector
+        */
+       public double getNorm() {
+               return Math.sqrt(getSquareNorm());
+       }
+       
+       /**
+        * @return square of the vector norm
+        */
+       public double getSquareNorm() {
+               return this.dotProduct(this);
+       }
+       
+       /**
+        * Normalize the vector
+        */
+       public void normalize() {
+               double norm = getNorm();
+               xCoord /= norm;
+               yCoord /= norm;
+               zCoord /= norm;
+       }
+       
+       /**
+        * Return a normalized vector of this
+        * @return new normalized vector
+        */
+       public Vector3D getNormalized() {
+               Vector3D res = new Vector3D(this);
+               res.normalize();
+               return res;
+       }
+       
+       /**
+        * Create the relut of mutiplying the vactor by a scalar
+        * @param scalar scalar to use
+        * @return new vector result of mutiplying this by a scalar
+        */
+       public Vector3D scalarMult(double scalar) {
+               return new Vector3D(scalar * xCoord, scalar * yCoord, scalar * zCoord);
+       }
+       
+       /**
+        * Compute the sum of the vector and an other
+        * @param v2 other vector
+        * @return new vector which is the sum of the two above
+        */
+       public Vector3D add(Vector3D v2) {
+               return new Vector3D(xCoord + v2.xCoord, yCoord + v2.yCoord, zCoord + v2.zCoord);
+       }
+       
+       /**
+        * Compute the difference of the vector and an other
+        * @param v2 other vector
+        * @return new vector, this - v2
+        */
+       public Vector3D substract(Vector3D v2) {
+               return new Vector3D(xCoord - v2.xCoord, yCoord - v2.yCoord, zCoord - v2.zCoord);
+       }
+       
+       /**
+        * Print the vector
+        * @return text of the vector
+        */
+       public String toString() {
+               final String comma = ", ";
+               return "[" + xCoord + comma + yCoord + comma + zCoord + "]";
+       }
+       
+}
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3D.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3D.java
new file mode 100644 (file)
index 0000000..684ec3d
--- /dev/null
@@ -0,0 +1,104 @@
+/*------------------------------------------------------------------------*/
+/* file: ClipPlane3D.java                                                 */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Plane which can be use to clip the scene                        */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer.utils.glTools;
+
+import org.scilab.modules.renderer.utils.geom3D.Plane3D;
+import org.scilab.modules.renderer.utils.geom3D.Vector3D;
+
+import javax.media.opengl.GL;
+
+/**
+ * Plane which can be use to clip the scene
+ * @author Jean-Baptiste Silvy
+ */
+public class ClipPlane3D extends Plane3D {
+
+       private static final int CLIP_PLANE_NOT_AVAILABLE = 0;
+       
+       
+       /** OpenGL index for the clip plane */
+       private int clipPlaneIndex = CLIP_PLANE_NOT_AVAILABLE;
+       
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param a first equation parameter
+        * @param b second equation parameter
+        * @param c third equation parameter
+        * @param d fourth equation parameter
+        */
+       public ClipPlane3D(double a, double b, double c, double d) {
+               super(a, b, c, d);
+       }
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param equation array of size 4 giving a, b, c and d
+        */
+       public ClipPlane3D(double[] equation) {
+               super(equation);
+       }
+       
+       /**
+        * Define a plane by giving three of its non aligned points
+        * @param point1 first point
+        * @param point2 second point
+        * @param point3 third point
+        */
+       public ClipPlane3D(Vector3D point1, Vector3D point2, Vector3D point3) {
+               super(point1, point2, point3);
+       }
+       
+       /**
+        * Default constructor. Should not be used, it does not create a valid plane.
+        */
+       protected ClipPlane3D() {
+               super();
+       }
+       
+       /**
+        * Clip all points wich does not verify a.x + b.y + c.z + d >= 0;
+        * @param gl current OpenGL pipeline
+        */
+       public void clip(GL gl) {
+               
+               if (clipPlaneIndex == CLIP_PLANE_NOT_AVAILABLE) {
+                       clipPlaneIndex = getAvailableClipPlane(gl);
+                       if (clipPlaneIndex == CLIP_PLANE_NOT_AVAILABLE) { return; }
+                       gl.glEnable(clipPlaneIndex);
+               }
+               
+               gl.glClipPlane(clipPlaneIndex, getEquation(), 0);
+       }
+       
+       
+       /**
+        * Remove the clipping
+        * @param gl current OpenGL pipeline
+        */
+       public void unClip(GL gl) {
+               gl.glDisable(clipPlaneIndex);
+               clipPlaneIndex = CLIP_PLANE_NOT_AVAILABLE;
+       }
+       
+       /**
+        * To know if there is a clipplane available
+        * @param gl current OpenGL pipeline
+        * @return true if there is a clip plane available, false otherwise
+        */
+       protected int getAvailableClipPlane(GL gl) {
+               for (int i = 0; i < GL.GL_MAX_CLIP_PLANES; i++) {
+                       if (!gl.glIsEnabled(GL.GL_CLIP_PLANE0 + i)) {
+                               // note that GL_CLIP_PLANEi == GL_CLIP_PLANE0 + i
+                               return GL.GL_CLIP_PLANE0 + i;
+                       }
+               }
+               return CLIP_PLANE_NOT_AVAILABLE;
+       }       
+}
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3DManager.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/ClipPlane3DManager.java
new file mode 100644 (file)
index 0000000..048102c
--- /dev/null
@@ -0,0 +1,105 @@
+/*------------------------------------------------------------------------*/
+/* file: MovableClipPlane3DManager.java                                   */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Store all clipped planes and change everyone of them            */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer.utils.glTools;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import javax.media.opengl.GL;
+
+/**
+ * Store all cliped planes and change everyone of them
+ * @author Jean-Baptiste Silvy
+ */
+public final class ClipPlane3DManager {
+       
+       /**
+        * List of clipplane. So every one can access the clipped planes
+        */
+       private static class ClipPlaneList extends LinkedList<MovableClipPlane3D> {
+               
+               /**
+                * Needed
+                */
+               private static final long serialVersionUID = 2435315256366L;
+
+               /**
+                * Default constructor
+                */
+               public ClipPlaneList() {
+                       super();
+               }
+       }
+       
+       /** List of all active clip planes */
+       private static ClipPlaneList activeClipPlanes = new ClipPlaneList();
+       
+       /**
+        * Default constructor should not be used
+        */
+       private ClipPlane3DManager() { }
+       
+       /**
+        * Add a new plane to the list of clipped planes
+        * @param plane plane to add
+        */
+       public static void addClippedPlane(MovableClipPlane3D plane) {
+               activeClipPlanes.add(plane);
+       }
+       
+       /**
+        * Remove a plane from the list of clipped planes
+        * @param plane plane to remove
+        */
+       public static void removeClippedPlane(MovableClipPlane3D plane) {
+               activeClipPlanes.remove(plane);
+       }
+       
+       /**
+        * @return Iterator on the list of currently active clip planes
+        */
+       public static Iterator<MovableClipPlane3D> getActiveClipPlanes() {
+               return activeClipPlanes.listIterator();
+       }
+       
+       /**
+        * Push all planes.
+        * @param gl current GL pipeline
+        */
+       public static void pushPlanes(GL gl) {
+               Iterator<MovableClipPlane3D> curPlaneIt = activeClipPlanes.iterator();
+               while (curPlaneIt.hasNext()) {
+                       curPlaneIt.next().pushPlane(gl);
+               }
+       }
+       
+       /**
+        * Pop all planes.
+        * @param gl current GL pipeline
+        */
+       public static void popAllPlanes(GL gl) {
+               Iterator<MovableClipPlane3D> curPlaneIt = activeClipPlanes.iterator();
+               while (curPlaneIt.hasNext()) {
+                       curPlaneIt.next().popPlane(gl);
+               }
+       }
+       
+       /**
+        * Change frame for all clipped planes
+        * @param gl current GL pipeline
+        */
+       public static void changeAllPlanesFrame(GL gl) {
+               Iterator<MovableClipPlane3D> curPlaneIt = activeClipPlanes.iterator();
+               while (curPlaneIt.hasNext()) {
+                       curPlaneIt.next().changeFrame(gl);
+               }
+
+               
+       }
+}
@@ -6,7 +6,7 @@
 /*------------------------------------------------------------------------*/
 
 
-package org.scilab.modules.renderer.utils;
+package org.scilab.modules.renderer.utils.glTools;
 
 import javax.media.opengl.GL;
 /**
@@ -22,8 +22,8 @@ public final class GLTools {
         * Actually when using gluProject z may vary between 0 and 1 (relative to depth buffer)
         * 0 is front clip plane and 1 back clip plane.
         */
-       public static final double MIN_PIXEL_Z = -0.1;
-       public static final double MAX_PIXEL_Z = 1.1;
+       public static final double MIN_PIXEL_Z = 0.0;
+       public static final double MAX_PIXEL_Z = 1.0;
        
        /** Contains the different line stipple pattern */
        private static final short[] STIPPLE_PATTERN
@@ -76,9 +76,10 @@ public final class GLTools {
         * @param gl current OpenGL pipeline
         */
        public static void usePixelCoordinates(GL gl) {
-               
                int[] viewPort = new int[VIEWPORT_LENGTH];
                
+               // clipping planes must be modified
+               ClipPlane3DManager.pushPlanes(gl);
                gl.glMatrixMode(GL.GL_PROJECTION);
                gl.glPushMatrix();
                gl.glLoadIdentity();
@@ -88,6 +89,7 @@ public final class GLTools {
                gl.glMatrixMode(GL.GL_MODELVIEW);
                gl.glPushMatrix();
                gl.glLoadIdentity();
+               ClipPlane3DManager.changeAllPlanesFrame(gl);
        }
        
        /**
@@ -100,6 +102,7 @@ public final class GLTools {
                gl.glPopMatrix();
                gl.glMatrixMode(GL.GL_MODELVIEW);
                gl.glPopMatrix();
+               ClipPlane3DManager.popAllPlanes(gl);
        }
        
 }
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/MovableClipPlane3D.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/glTools/MovableClipPlane3D.java
new file mode 100644 (file)
index 0000000..fb0e746
--- /dev/null
@@ -0,0 +1,158 @@
+/*------------------------------------------------------------------------*/
+/* file: MovableClipPlane3D.java                                          */
+/* Copyright INRIA 2007                                                   */
+/* Authors : Jean-Baptiste Silvy                                          */
+/* desc : Plane which can be used in different coodinates transformations */
+/*------------------------------------------------------------------------*/
+
+
+package org.scilab.modules.renderer.utils.glTools;
+import java.util.LinkedList;
+
+import javax.media.opengl.GL;
+
+import org.scilab.modules.renderer.utils.CoordinateTransformation;
+import org.scilab.modules.renderer.utils.geom3D.Plane3D;
+import org.scilab.modules.renderer.utils.geom3D.Vector3D;
+
+/**
+ * Plane which can be used in different coodinates transformations
+ * @author Jean-Baptiste Silvy
+ */
+public class MovableClipPlane3D extends ClipPlane3D {
+
+       
+       /**
+        * Saved previous clipped planes to restore them after
+        */
+       private class ClipPlanePile extends LinkedList<Plane3D> {
+               
+               /**
+                * Needed
+                */
+               private static final long serialVersionUID = 2435397256366L;
+
+               /**
+                * Default constructor
+                */
+               public ClipPlanePile() {
+                       super();
+               }
+       }
+       
+       
+       private Vector3D point1 = new Vector3D();
+       private Vector3D point2 = new Vector3D();
+       private Vector3D point3 = new Vector3D();
+       
+       /** List of all pushed planes */
+       private ClipPlanePile pushedPlanes = new ClipPlanePile();
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param a first equation parameter
+        * @param b second equation parameter
+        * @param c third equation parameter
+        * @param d fourth equation parameter
+        */
+       public MovableClipPlane3D(double a, double b, double c, double d) {
+               super(a, b, c, d);
+       }
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param equation array of size 4 giving a, b, c and d
+        */
+       public MovableClipPlane3D(double[] equation) {
+               super(equation);
+       }
+       
+       /**
+        * Define a plane by giving the equation a.x + b.y + c.z + d = 0
+        * @param copyPlane the plane to copy
+        */
+       public MovableClipPlane3D(Plane3D copyPlane) {
+               super(copyPlane.getEquation());
+       }
+       
+       /**
+        * Define a plane by giving three of its non aligned points
+        * @param point1 first point
+        * @param point2 second point
+        * @param point3 third point
+        */
+       public MovableClipPlane3D(Vector3D point1, Vector3D point2, Vector3D point3) {
+               super(point1, point2, point3);
+       }
+       
+       /**
+        * Default constructor. Should not be used, it does not create a valid plane.
+        */
+       protected MovableClipPlane3D() {
+               super();
+       }
+       
+       /**
+        * Clip all points wich does not verify a.x + b.y + c.z + d >= 0;
+        * @param gl current OpenGL pipeline
+        */
+       @Override
+       public void clip(GL gl) {
+               super.clip(gl);
+               ClipPlane3DManager.addClippedPlane(this);
+       }
+       
+       /**
+        * Remove the clipping
+        * @param gl current OpenGL pipeline
+        */
+       @Override
+       public void unClip(GL gl) {
+               super.unClip(gl);
+               ClipPlane3DManager.removeClippedPlane(this);
+       }
+       
+       /**
+        * Save the current plane equation befaore a coordinate transformation
+        * @param gl current OpenGL pipeline
+        */
+       public void pushPlane(GL gl) {
+
+               Plane3D copyPlane = new Plane3D(this);
+               pushedPlanes.push(copyPlane);
+               
+               
+               getThreePointsOnPlane(point1, point2, point3);
+               point1 = CoordinateTransformation.getTransformation().getCanvasCoordinates(gl, point1);
+               point2 = CoordinateTransformation.getTransformation().getCanvasCoordinates(gl, point2);
+               point3 = CoordinateTransformation.getTransformation().getCanvasCoordinates(gl, point3);
+                       
+       }
+       
+       /**
+        * Recompute the plane using the current frame
+        * @param gl current OpenGL pipeline
+        */
+       public void changeFrame(GL gl) {
+
+               CoordinateTransformation transform = CoordinateTransformation.getTransformation();
+               
+               Vector3D newPoint1 = transform.retrieveSceneCoordinates(gl, point1);
+               Vector3D newPoint2 = transform.retrieveSceneCoordinates(gl, point2);
+               Vector3D newPoint3 = transform.retrieveSceneCoordinates(gl, point3);
+               
+               this.setEquation(newPoint1, newPoint2, newPoint3);
+               super.clip(gl); // not just clip, otherwise the plane will be added to the list of clipped planes
+       }
+       
+       /**
+        * Restore the previous plane when coming back to previous coordinate transformations
+        * @param gl current OpenGL pipeline
+        */
+       public void popPlane(GL gl) {
+               Plane3D restoredPlane = pushedPlanes.pop();
+               this.setEquation(restoredPlane.getEquation());
+               super.clip(gl); // not just clip, otherwise the plane will be added to the list of clipped planes
+       }
+       
+}