0024622: Add method to AIS_TexturedShape class to assign texture data directly from...
authorapl <apl@opencascade.com>
Thu, 6 Mar 2014 10:15:39 +0000 (14:15 +0400)
committerabv <abv@opencascade.com>
Thu, 6 Mar 2014 11:48:03 +0000 (15:48 +0400)
Added methods to specify Image_PixMap as texture source to AIS_TexturedShape and Graphic3d_TextureRoot.
Modified internal class MeshVS_ImageTexture2D, originally used for the purpose of sourcing texture as Image_PixMap.

AIS_TexturedShape class:
- Get rid from cdl declaration.
- Remove unused and uninitialized field myDeflection / method Deflection().
- Improve class documentation.
- Use Graphic3d_NOT_2D_UNKNOWN instead of -1.
- Use myIsCustomOrigin and myToScale flags to use/ignore custom values.

24 files changed:
src/AIS/AIS.cdl
src/AIS/AIS_TexturedShape.cdl [deleted file]
src/AIS/AIS_TexturedShape.cxx
src/AIS/AIS_TexturedShape.hxx [new file with mode: 0644]
src/AIS/FILES
src/Graphic3d/Graphic3d_Texture1D.cdl
src/Graphic3d/Graphic3d_Texture1D.cxx
src/Graphic3d/Graphic3d_Texture1Dmanual.cdl
src/Graphic3d/Graphic3d_Texture1Dmanual.cxx
src/Graphic3d/Graphic3d_Texture1Dsegment.cdl
src/Graphic3d/Graphic3d_Texture1Dsegment.cxx
src/Graphic3d/Graphic3d_Texture2D.cdl
src/Graphic3d/Graphic3d_Texture2D.cxx
src/Graphic3d/Graphic3d_Texture2Dmanual.cdl
src/Graphic3d/Graphic3d_Texture2Dmanual.cxx
src/Graphic3d/Graphic3d_Texture2Dplane.cdl
src/Graphic3d/Graphic3d_Texture2Dplane.cxx
src/Graphic3d/Graphic3d_TextureMap.cdl
src/Graphic3d/Graphic3d_TextureMap.cxx
src/Graphic3d/Graphic3d_TextureRoot.cdl
src/Graphic3d/Graphic3d_TextureRoot.cxx
src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx
src/QABugs/QABugs_19.cxx
tests/bugs/vis/bug24622 [new file with mode: 0644]

index b0445e5..f772d4e 100644 (file)
@@ -146,7 +146,8 @@ uses
     StdSelect,
     DsgPrs,
     TopTools,
-    Poly
+    Poly,
+    Image
 
 is
     
@@ -324,7 +325,7 @@ is
 
     class Triangulation;
 
-    class TexturedShape;
+    imported TexturedShape;
 
     class Drawer;
     
diff --git a/src/AIS/AIS_TexturedShape.cdl b/src/AIS/AIS_TexturedShape.cdl
deleted file mode 100644 (file)
index 0f2f406..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
--- Created on: 2001-07-02
--- Created by: Mathias BOSSHARD
--- Copyright (c) 2001-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
-class TexturedShape from AIS inherits Shape from AIS
-
-       ---Purpose: This class allows to map textures on shapes
-       --  Textures are image files.
-       --   The texture itself is parametrized in (0,1)x(0,1).
-       --  Each face of a shape located in
-       -- UV space is provided with these parameters:
-       --    -      Umin - starting position in U
-       --    -      Umax - ending position in U
-       --    -      Vmin - starting position in V
-       --    -      Vmax - ending position in V
-       --  Each face is triangulated and a texel is assigned to each 
-       --  node. Facets are then filled using a linear interpolation 
-       --  of texture between each 'three texels'                              
-       --  User can act on :
-       --  - the number of occurences of the texture on the face
-       --  - the position of the origin of the texture
-       --  - the scale factor of the texture
-          
-
-
-uses    
-    Pnt                   from gp,
-    Shape                 from TopoDS,
-    NameOfTexture2D       from Graphic3d,
-    AspectFillArea3d      from Graphic3d,
-    Texture2Dmanual       from Graphic3d,
-    PresentationManager3d from PrsMgr,
-    Presentation          from Prs3d,
-    AsciiString           from TCollection
-
-is
-
-    Create (shap: Shape from TopoDS) 
-    returns mutable TexturedShape from AIS;
-       ---Purpose:      Initializes the textured shape ashape.
-
-
-    ------------------------------------------------------------
-    SetTextureFileName( me: mutable;
-                        TextureFileName: AsciiString from TCollection)
-    is virtual;
-    ---Purpose : Sets the name of the texture file to map. The accepted
-    --      file types are those used in Image_AlienPixMap with extensions
-    --      such as rgb, png, jpg and more.
-
-
-    ------------------------------------------------------------
-    SetTextureRepeat(   me: mutable; 
-                       RepeatYN: Boolean from Standard; 
-                       URepeat: Real from Standard = 1.0; 
-                       VRepeat: Real from Standard = 1.0)
-    is virtual;
-                       
-                       
-       ---Purpose : Sets the number of occurrences of
-       -- the texture on each face. The texture itself is parameterized
-       -- in (0,1) by (0,1) . Each face of the shape to be textured is
-       -- parameterized in UV space (Umin,Umax) by (Vmin,Vmax). If
-       -- RepeatYN is set to false, texture coordinates are clamped in the
-       -- range (0,1)x(0,1) of the face. 
-  
-
-    ------------------------------------------------------------
-    SetTextureOrigin(   me: mutable; 
-                       SetTextureOriginYN: Boolean from Standard; 
-                       UOrigin: Real from Standard = 0.0; 
-                       VOrigin: Real from Standard = 0.0)
-    is virtual;
-
-       ---Purpose : Use this method to change the origin of the 
-       --         texture. The texel (0,0) will be mapped to the 
-       --         surfel (UOrigin,VOrigin)
-    ------------------------------------------------------------
-   
-   
-     
-    ------------------------------------------------------------
-    SetTextureScale(    me: mutable; 
-                       SetTextureScaleYN: Boolean from Standard; 
-                       ScaleU: Real from Standard = 1.0; 
-                       ScaleV: Real from Standard = 1.0)
-    is virtual;   
-   
-
-       ---Purpose : Use this method to scale the texture (percent of
-       --         the face).
-       --         You can specify a scale factor for both U and V.
-       --         
-       --         example : if you set ScaleU and ScaleV to 0.5 and
-       --         you enable texture repeat, the texture will appear
-       --         twice on the face in each direction.
-    ------------------------------------------------------------
-
-
-   
-    ------------------------------------------------------------
-    ShowTriangles(  me : mutable; 
-                   ShowTrianglesYN: Boolean from Standard = Standard_False)
-    is virtual;
-    
-    
-       ---Purpose : Use this method to show the triangulation of 
-       --         the shape. This is not very esthetic but can be 
-       --         usefull for debug ... 
-    ------------------------------------------------------------
-
-    
-
-    ------------------------------------------------------------
-    SetTextureMapOn(me: mutable);
-   
-       ---Purpose : Enables texture mapping    
-    ------------------------------------------------------------
-   
-   
-
-    ------------------------------------------------------------
-    SetTextureMapOff(me: mutable);
-   
-       ---Purpose : Disables texture mapping    
-    ------------------------------------------------------------
-      
-   
-
-    ------------------------------------------------------------
-    EnableTextureModulate(me: mutable);
-   
-       ---Purpose : Enables texture modulation
-    ------------------------------------------------------------
-      
-
-
-    ------------------------------------------------------------
-    DisableTextureModulate(me: mutable);
-   
-       ---Purpose : Disables texture modulation    
-    ------------------------------------------------------------
-      
-   
-
-    ------------------------------------------------------------
-    UpdateAttributes(me: mutable);
-
-       ---Purpose : Use this method to display the textured shape 
-       --         without recomputing the whole presentation.
-       --         Use this method when ONLY the texture has been changed.
-       --         ie : myTShape->UpdateAttributes()
-       --          
-       --         If other parameters (ie: scale factors,
-       --         texture origin, texture repeat ...) have changed,
-       --         the whole presentation has to be recomputed.
-       --         ie : if (myShape->DisplayMode() == 3)
-       --                     myAISContext->RecomputePrsOnly(myShape);
-       --                  else
-       --                     {
-       --                       myAISContext->SetDisplayMode(myShape,3,Standard_False);
-       --                       myAISContext->Display(myShape, Standard_True);
-       --                     } 
-    ------------------------------------------------------------
-   
-   
-    
-    ------------------------------------------------------------
-    Compute(me                   : mutable;
-           aPresentationManager : PresentationManager3d from PrsMgr;
-            aPresentation        : mutable Presentation from Prs3d;
-           aMode                : Integer from Standard = 0) 
-    is redefined virtual protected;
-    
-    ------------------------------------------------------------
-   
-    ------------------------------------------------------------
-    --          
-    --          QUERY METHODS
-    --          
-    ------------------------------------------------------------
-    
-    
-    TextureMapState(me) returns Boolean from Standard;
-    
-
-    URepeat(me)         returns Real    from Standard;
-    
-
-    TextureRepeat(me)   returns Boolean from Standard;
-    
-    
-    Deflection(me)      returns Real    from Standard;
-    
-    
-    TextureFile(me)     returns CString from Standard;
-    
-
-    VRepeat(me)         returns Real    from Standard;
-    
-
-    ShowTriangles(me)   returns Boolean from Standard;
-    
-
-    TextureUOrigin(me)  returns Real    from Standard;
-    
-    
-    TextureVOrigin(me)  returns Real    from Standard;
-    
-
-    TextureScaleU(me)   returns Real    from Standard;
-    
-
-    TextureScaleV(me)   returns Real    from Standard;
-    
-
-    TextureScale(me)    returns Boolean from Standard;
-    
-
-    TextureOrigin(me)   returns Boolean from Standard;
-    
-
-    TextureModulate(me) returns Boolean from Standard;
-    
-    
-fields
-    myPredefTexture    : NameOfTexture2D  from Graphic3d;
-    myTextureFile      : AsciiString      from TCollection;
-    DoRepeat           : Boolean          from Standard;
-    myURepeat          : Real             from Standard;
-    myVRepeat          : Real             from Standard;
-    DoMapTexture       : Boolean          from Standard;
-    DoSetTextureOrigin : Boolean          from Standard;
-    myUOrigin          : Real             from Standard;
-    myVOrigin          : Real             from Standard;
-    DoSetTextureScale  : Boolean          from Standard;
-    myScaleU           : Real             from Standard;
-    myScaleV           : Real             from Standard;
-    DoShowTriangles    : Boolean          from Standard;
-    myDeflection       : Real             from Standard;
-    myAspect           : AspectFillArea3d from Graphic3d;
-    mytexture          : Texture2Dmanual  from Graphic3d;
-    myModulate         : Boolean          from Standard;
-end TexturedShape;
index 64e4f2c..8b39861 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-// Modified:
-////////////////////////////////////////////////////////////////////////
-
-
-#include <AIS_TexturedShape.ixx>
-#include <Standard_ErrorHandler.hxx>
+#include <AIS_TexturedShape.hxx>
 
 #include <AIS_Drawer.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <Prs3d_Root.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <PrsMgr_PresentationManager3d.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <StdPrs_ShadedShape.hxx>
 #include <StdPrs_WFDeflectionShape.hxx>
 #include <StdPrs_WFShape.hxx>
 #include <TopExp_Explorer.hxx>
 
+IMPLEMENT_STANDARD_HANDLE (AIS_TexturedShape, AIS_Shape)
+IMPLEMENT_STANDARD_RTTIEXT(AIS_TexturedShape, AIS_Shape)
+
 //=======================================================================
 //function : AIS_TexturedShape
 //purpose  :
 //=======================================================================
 AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape)
-: AIS_Shape (theShape),
-  myPredefTexture (Graphic3d_NameOfTexture2D(0)),
-  myTextureFile (""),
-  DoRepeat (Standard_True),
-  myURepeat (1.0),
-  myVRepeat (1.0),
-  DoMapTexture (Standard_True),
-  DoSetTextureOrigin (Standard_True),
-  myUOrigin (0.0),
-  myVOrigin (0.0),
-  DoSetTextureScale (Standard_True),
-  myScaleU (1.0),
-  myScaleV (1.0),
-  DoShowTriangles (Standard_False),
-  myModulate (Standard_True)
+: AIS_Shape         (theShape),
+  myPredefTexture   (Graphic3d_NameOfTexture2D(0)),
+  myToMapTexture    (Standard_True),
+  myModulate        (Standard_True),
+  myUVOrigin        (0.0, 0.0),
+  myIsCustomOrigin  (Standard_True),
+  myUVRepeat        (1.0, 1.0),
+  myToRepeat        (Standard_True),
+  myUVScale         (1.0, 1.0),
+  myToScale         (Standard_True),
+  myToShowTriangles (Standard_False)
 {
 }
 
@@ -67,16 +62,19 @@ AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape)
 //=======================================================================
 void AIS_TexturedShape::SetTextureFileName (const TCollection_AsciiString& theTextureFileName)
 {
+  myTexturePixMap.Nullify();
+
   if (theTextureFileName.IsIntegerValue())
   {
-    if (theTextureFileName.IntegerValue() < Graphic3d_Texture2D::NumberOfTextures()
-     && theTextureFileName.IntegerValue() >= 0)
+    const Standard_Integer aValue = theTextureFileName.IntegerValue();
+    if (aValue < Graphic3d_Texture2D::NumberOfTextures()
+     && aValue >= 0)
     {
-      myPredefTexture = Graphic3d_NameOfTexture2D (theTextureFileName.IntegerValue());
+      myPredefTexture = Graphic3d_NameOfTexture2D (aValue);
     }
     else
     {
-      std::cout << "Texture " << theTextureFileName << " doesn't exist \n";
+      std::cout << "Texture " << theTextureFileName << " doesn't exist\n";
       std::cout << "Using Texture 0 instead ...\n";
       myPredefTexture = Graphic3d_NameOfTexture2D (0);
     }
@@ -85,22 +83,32 @@ void AIS_TexturedShape::SetTextureFileName (const TCollection_AsciiString& theTe
   else
   {
     myTextureFile   = theTextureFileName;
-    myPredefTexture = Graphic3d_NameOfTexture2D (-1);
+    myPredefTexture = Graphic3d_NOT_2D_UNKNOWN;
   }
 }
 
+//=======================================================================
+//function : SetTexturePixMap
+//purpose  :
+//=======================================================================
+void AIS_TexturedShape::SetTexturePixMap (const Handle(Image_PixMap)& theTexturePixMap)
+{
+  myTextureFile = "";
+  myPredefTexture = Graphic3d_NOT_2D_UNKNOWN;
+  myTexturePixMap = theTexturePixMap;
+}
+
 //=======================================================================
 //function : SetTextureRepeat
 //purpose  :
 //=======================================================================
 
-void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theRepeatYN,
+void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theToRepeat,
                                           const Standard_Real    theURepeat,
                                           const Standard_Real    theVRepeat)
 {
-  DoRepeat  = theRepeatYN;
-  myURepeat = theURepeat;
-  myVRepeat = theVRepeat;
+  myToRepeat = theToRepeat;
+  myUVRepeat.SetCoord (theURepeat, theVRepeat);
 }
 
 //=======================================================================
@@ -110,7 +118,7 @@ void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theRepeatYN,
 
 void AIS_TexturedShape::SetTextureMapOn()
 {
-  DoMapTexture = Standard_True;
+  myToMapTexture = Standard_True;
 }
 
 //=======================================================================
@@ -120,7 +128,7 @@ void AIS_TexturedShape::SetTextureMapOn()
 
 void AIS_TexturedShape::SetTextureMapOff()
 {
-  DoMapTexture = Standard_False;
+  myToMapTexture = Standard_False;
 }
 
 //=======================================================================
@@ -128,13 +136,12 @@ void AIS_TexturedShape::SetTextureMapOff()
 //purpose  :
 //=======================================================================
 
-void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean toSetTextureOriginYN,
+void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean theToSetTextureOrigin,
                                           const Standard_Real    theUOrigin,
                                           const Standard_Real    theVOrigin)
 {
-  DoSetTextureOrigin = toSetTextureOriginYN;
-  myUOrigin = theUOrigin;
-  myVOrigin = theVOrigin;
+  myIsCustomOrigin = theToSetTextureOrigin;
+  myUVOrigin.SetCoord (theUOrigin, theVOrigin);
 }
 
 //=======================================================================
@@ -142,13 +149,12 @@ void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean toSetTextureOri
 //purpose  :
 //=======================================================================
 
-void AIS_TexturedShape::SetTextureScale (const Standard_Boolean toSetTextureScaleYN,
+void AIS_TexturedShape::SetTextureScale (const Standard_Boolean theToSetTextureScale,
                                          const Standard_Real    theScaleU,
                                          const Standard_Real    theScaleV)
 {
-  DoSetTextureScale = toSetTextureScaleYN;
-  myScaleU = theScaleU;
-  myScaleV = theScaleV;
+  myToScale = theToSetTextureScale;
+  myUVScale.SetCoord (theScaleU, theScaleV);
 }
 
 //=======================================================================
@@ -156,9 +162,9 @@ void AIS_TexturedShape::SetTextureScale (const Standard_Boolean toSetTextureScal
 //purpose  :
 //=======================================================================
 
-void AIS_TexturedShape::ShowTriangles (const Standard_Boolean toShowTrianglesYN)
+void AIS_TexturedShape::ShowTriangles (const Standard_Boolean theToShowTriangles)
 {
-  DoShowTriangles = toShowTrianglesYN;
+  myToShowTriangles = theToShowTriangles;
 }
 
 //=======================================================================
@@ -191,27 +197,35 @@ void AIS_TexturedShape::UpdateAttributes()
   Prs3d_ShadingAspect aDummy;
   myAspect = aDummy.Aspect();
   Handle(Prs3d_Presentation) aPrs = Presentation();
-  if (!DoMapTexture)
+  if (!myToMapTexture)
   {
     myAspect->SetTextureMapOff();
     return;
   }
 
-  if (myPredefTexture != -1)
-    mytexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
+  if (!myTexturePixMap.IsNull())
+  {
+    myTexture = new Graphic3d_Texture2Dmanual (myTexturePixMap);
+  }
+  else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN)
+  {
+    myTexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
+  }
   else
-    mytexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
+  {
+    myTexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
+  }
 
   myAspect->SetTextureMapOn();
 
-  myAspect->SetTextureMap (mytexture);
-  if (!mytexture->IsDone())
+  myAspect->SetTextureMap (myTexture);
+  if (!myTexture->IsDone())
   {
-    std::cout << "An error occured while building texture \n";
+    std::cout << "An error occurred while building texture \n";
     return;
   }
 
-  if (DoShowTriangles)
+  if (myToShowTriangles)
     myAspect->SetEdgeOn();
   else
     myAspect->SetEdgeOff();
@@ -224,7 +238,7 @@ void AIS_TexturedShape::UpdateAttributes()
 //purpose  :
 //=======================================================================
 
-void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresManager*/,
+void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
                                  const Handle(Prs3d_Presentation)&           thePrs,
                                  const Standard_Integer                      theMode)
 {
@@ -257,12 +271,12 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
 
   switch (theMode)
   {
-    case 0: // Wireframe
+    case AIS_WireFrame:
     {
       StdPrs_WFDeflectionShape::Add (thePrs, myshape, myDrawer);
       break;
     }
-    case 1: // Shading
+    case AIS_Shaded:
     {
       Standard_Real prevangle;
       Standard_Real newangle;
@@ -298,7 +312,6 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
       }
       break;
     }
-
     case 2: // Bounding box
     {
       if (IsInfinite())
@@ -311,10 +324,9 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
       }
       break;
     }
-
     case 3: // texture mapping on triangulation
     {
-      BRepTools::Clean (myshape);
+      BRepTools::Clean  (myshape);
       BRepTools::Update (myshape);
 
       {
@@ -330,48 +342,56 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
           myAspect->SetPolygonOffsets(aMode, aFactor, aUnits);
         }
       }
-      if (!DoMapTexture)
+      if (!myToMapTexture)
       {
         myAspect->SetTextureMapOff();
         return;
       }
       myAspect->SetTextureMapOn();
 
-      if (myPredefTexture != -1)
-        mytexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
+      if (!myTexturePixMap.IsNull())
+      {
+        myTexture = new Graphic3d_Texture2Dmanual (myTexturePixMap);
+      }
+      else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN)
+      {
+        myTexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
+      }
       else
-        mytexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
+      {
+        myTexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
+      }
 
-      if (!mytexture->IsDone())
+      if (!myTexture->IsDone())
       {
-        std::cout << "An error occured while building texture \n";
+        std::cout << "An error occurred while building texture \n";
         return;
       }
 
       if (myModulate)
-        mytexture->EnableModulate();
+        myTexture->EnableModulate();
       else
-        mytexture->DisableModulate();
+        myTexture->DisableModulate();
 
-      myAspect->SetTextureMap (mytexture);
-      if (DoShowTriangles)
+      myAspect->SetTextureMap (myTexture);
+      if (myToShowTriangles)
         myAspect->SetEdgeOn();
       else
         myAspect->SetEdgeOff();
 
-      if (DoRepeat)
-        mytexture->EnableRepeat();
+      if (myToRepeat)
+        myTexture->EnableRepeat();
       else
-        mytexture->DisableRepeat();
+        myTexture->DisableRepeat();
 
-      const gp_Pnt2d aUVOrigin (myUOrigin, myVOrigin);
-      const gp_Pnt2d aUVRepeat (myURepeat, myVRepeat);
-      const gp_Pnt2d aUVScale  (myScaleU,  myScaleV);
       try
       {
         OCC_CATCH_SIGNALS
         StdPrs_ShadedShape::Add (thePrs, myshape, myDrawer,
-                                 Standard_True, aUVOrigin, aUVRepeat, aUVScale);
+                                 Standard_True,
+                                 myIsCustomOrigin ? myUVOrigin : gp_Pnt2d (0.0, 0.0),
+                                 myUVRepeat,
+                                 myToScale        ? myUVScale  : gp_Pnt2d (1.0, 1.0));
         // within primitive arrays - object should be in one group of primitives
         Prs3d_Root::CurrentGroup (thePrs)->SetGroupPrimitivesAspect (myAspect);
       }
@@ -384,73 +404,3 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
     }
   }
 }
-
-Standard_Boolean AIS_TexturedShape::TextureMapState() const
-{
-  return DoMapTexture;
-}
-
-Standard_Real AIS_TexturedShape::URepeat() const
-{
-  return myURepeat;
-}
-
-Standard_Boolean AIS_TexturedShape::TextureRepeat() const
-{
-  return DoRepeat;
-}
-
-Standard_Real AIS_TexturedShape::Deflection() const
-{
-  return myDeflection;
-}
-
-Standard_CString AIS_TexturedShape::TextureFile() const
-{
-  return myTextureFile.ToCString();
-}
-
-Standard_Real AIS_TexturedShape::VRepeat() const
-{
-  return myVRepeat;
-}
-
-Standard_Boolean AIS_TexturedShape::ShowTriangles() const
-{
-  return DoShowTriangles;
-}
-
-Standard_Real AIS_TexturedShape::TextureUOrigin() const
-{
-  return myUOrigin;
-}
-
-Standard_Real AIS_TexturedShape::TextureVOrigin() const
-{
-  return myVOrigin;
-}
-
-Standard_Real AIS_TexturedShape::TextureScaleU() const
-{
-  return myScaleU;
-}
-
-Standard_Real AIS_TexturedShape::TextureScaleV() const
-{
-  return myScaleV;
-}
-
-Standard_Boolean AIS_TexturedShape::TextureScale() const
-{
-  return DoSetTextureScale;
-}
-
-Standard_Boolean AIS_TexturedShape::TextureOrigin() const
-{
-  return DoSetTextureOrigin;
-}
-
-Standard_Boolean AIS_TexturedShape::TextureModulate() const
-{
-  return myModulate;
-}
diff --git a/src/AIS/AIS_TexturedShape.hxx b/src/AIS/AIS_TexturedShape.hxx
new file mode 100644 (file)
index 0000000..8ca7390
--- /dev/null
@@ -0,0 +1,205 @@
+// Created on: 2001-07-02
+// Created by: Mathias BOSSHARD
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _AIS_TexturedShape_HeaderFile
+#define _AIS_TexturedShape_HeaderFile
+
+#include <AIS_Shape.hxx>
+#include <gp_Pnt2d.hxx>
+#include <Graphic3d_NameOfTexture2D.hxx>
+#include <Image_PixMap.hxx>
+#include <Standard_DefineHandle.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <Handle_Graphic3d_AspectFillArea3d.hxx>
+#include <Handle_Graphic3d_Texture2Dmanual.hxx>
+#include <Handle_Prs3d_Presentation.hxx>
+#include <Handle_PrsMgr_PresentationManager3d.hxx>
+
+class Graphic3d_AspectFillArea3d;
+class Graphic3d_Texture2Dmanual;
+class TopoDS_Shape;
+class TCollection_AsciiString;
+class PrsMgr_PresentationManager3d;
+class Prs3d_Presentation;
+
+//! This class allows to map textures on shapes.
+//! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in AIS_Shape,
+//! whilst new modes 2 (bounding box) and 3 (texture mapping) extends it functionality.
+//!
+//! The texture itself is parametrized in (0,1)x(0,1).
+//! Each face of a shape located in UV space is provided with these parameters:
+//! - Umin - starting position in U
+//! - Umax - ending   position in U
+//! - Vmin - starting position in V
+//! - Vmax - ending   position in V
+//! Each face is triangulated and a texel is assigned to each node.
+//! Facets are then filled using a linear interpolation of texture between each 'three texels'.
+//! User can act on:
+//! - the number of occurrences of the texture on the face
+//! - the position of the origin of the texture
+//! - the scale factor of the texture
+class AIS_TexturedShape : public AIS_Shape
+{
+
+public: //! @name main methods
+
+  //! Initializes the textured shape.
+  Standard_EXPORT AIS_TexturedShape (const TopoDS_Shape& theShape);
+
+  //! Sets the texture source. <theTextureFileName> can specify path to texture image or one of the standard predefined textures.
+  //! The accepted file types are those used in Image_AlienPixMap with extensions such as rgb, png, jpg and more.
+  //! To specify the standard predefined texture, the <theTextureFileName> should contain integer - the Graphic3d_NameOfTexture2D enumeration index.
+  //! Setting texture source using this method resets the source pixmap (if was set previously).
+  Standard_EXPORT virtual void SetTextureFileName (const TCollection_AsciiString& theTextureFileName);
+
+  //! Sets the texture source. <theTexturePixMap> specifies image data.
+  //! Please note that the data should be in Bottom-Up order, the flag of Image_PixMap::IsTopDown() will be ignored by graphic driver.
+  //! Setting texture source using this method resets the source by filename (if was set previously).
+  Standard_EXPORT virtual void SetTexturePixMap (const Image_PixMap_Handle& theTexturePixMap);
+
+  //! @return flag to control texture mapping (for presentation mode 3)
+  Standard_Boolean TextureMapState() const { return myToMapTexture; }
+
+  //! Enables texture mapping
+  Standard_EXPORT void SetTextureMapOn();
+
+  //! Disables texture mapping
+  Standard_EXPORT void SetTextureMapOff();
+
+  //! @return path to the texture file
+  Standard_CString TextureFile() const { return myTextureFile.ToCString(); }
+
+  //! @return the source pixmap for texture map
+  const Handle(Image_PixMap)& TexturePixMap() const { return myTexturePixMap; }
+
+public: //! @name methods to alter texture mapping properties
+
+  //! Use this method to display the textured shape without recomputing the whole presentation.
+  //! Use this method when ONLY the texture content has been changed.
+  //! If other parameters (ie: scale factors, texture origin, texture repeat...) have changed, the whole presentation has to be recomputed:
+  //! @code
+  //! if (myShape->DisplayMode() == 3)
+  //! {
+  //!   myAISContext->RecomputePrsOnly (myShape);
+  //! }
+  //! else
+  //! {
+  //!   myAISContext->SetDisplayMode (myShape, 3, Standard_False);
+  //!   myAISContext->Display        (myShape, Standard_True);
+  //! }
+  //! @endcode
+  Standard_EXPORT void UpdateAttributes();
+
+  //! Enables texture modulation
+  Standard_EXPORT void EnableTextureModulate();
+
+  //! Disables texture modulation
+  Standard_EXPORT void DisableTextureModulate();
+
+  //! @return texture repeat flag
+  Standard_Boolean TextureRepeat() const { return myToRepeat; }
+
+  //! @return texture repeat U value
+  Standard_Real URepeat() const { return myUVRepeat.X(); }
+
+  //! @return texture repeat V value
+  Standard_Real VRepeat() const { return myUVRepeat.Y(); }
+
+  //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
+  //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
+  //! If RepeatYN is set to false, texture coordinates are clamped in the range (0,1)x(0,1) of the face.
+  Standard_EXPORT void SetTextureRepeat (const Standard_Boolean theToRepeat,
+                                         const Standard_Real    theURepeat = 1.0,
+                                         const Standard_Real    theVRepeat = 1.0);
+
+  //! @return true if texture UV origin has been modified
+  Standard_Boolean TextureOrigin() const { return myIsCustomOrigin; }
+
+  //! @return texture origin U position (0.0 by default)
+  Standard_Real TextureUOrigin() const { return myUVOrigin.X(); }
+
+  //! @return texture origin V position (0.0 by default)
+  Standard_Real TextureVOrigin() const { return myUVOrigin.Y(); }
+
+  //! Use this method to change the origin of the texture. The texel (0,0) will be mapped to the surface (UOrigin,VOrigin)
+  Standard_EXPORT void SetTextureOrigin (const Standard_Boolean theToSetTextureOrigin,
+                                         const Standard_Real    theUOrigin = 0.0,
+                                         const Standard_Real    theVOrigin = 0.0);
+
+  //! @return true if scale factor should be applied to texture mapping
+  Standard_Boolean TextureScale() const { return myToScale; }
+
+  //! @return scale factor for U coordinate (1.0 by default)
+  Standard_Real TextureScaleU() const { return myUVScale.X(); }
+
+  //! @return scale factor for V coordinate (1.0 by default)
+  Standard_Real TextureScaleV() const { return myUVScale.Y(); }
+
+  //! Use this method to scale the texture (percent of the face).
+  //! You can specify a scale factor for both U and V.
+  //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
+  //!          the texture will appear twice on the face in each direction.
+  Standard_EXPORT void SetTextureScale (const Standard_Boolean theToSetTextureScale,
+                                        const Standard_Real    theScaleU = 1.0,
+                                        const Standard_Real    theScaleV = 1.0);
+
+  //! @return true if displaying of triangles is requested
+  Standard_Boolean ShowTriangles() const { return myToShowTriangles; }
+
+  //! Use this method to show the triangulation of the shape (for debugging etc.).
+  Standard_EXPORT void ShowTriangles (const Standard_Boolean theToShowTriangles = Standard_False);
+
+  //! @return true if texture color modulation is turned on
+  Standard_Boolean TextureModulate() const { return myModulate; }
+
+protected: //! @name overridden methods
+
+  //! Compute presentation with texture mapping support.
+  Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
+                                        const Handle(Prs3d_Presentation)&           thePrs,
+                                        const Standard_Integer                      theMode);
+
+protected: //! @name presentation fields
+
+  Handle(Graphic3d_Texture2Dmanual)  myTexture;
+  Handle(Graphic3d_AspectFillArea3d) myAspect;
+
+protected: //! @name texture source fields
+
+  Handle(Image_PixMap)               myTexturePixMap;
+  TCollection_AsciiString            myTextureFile;
+  Graphic3d_NameOfTexture2D          myPredefTexture;
+
+protected: //! @name texture mapping properties
+
+  Standard_Boolean                   myToMapTexture;
+  Standard_Boolean                   myModulate;
+  gp_Pnt2d                           myUVOrigin;
+  Standard_Boolean                   myIsCustomOrigin;
+  gp_Pnt2d                           myUVRepeat;
+  Standard_Boolean                   myToRepeat;
+  gp_Pnt2d                           myUVScale;
+  Standard_Boolean                   myToScale;
+  Standard_Boolean                   myToShowTriangles;
+
+public:
+
+  DEFINE_STANDARD_RTTI (AIS_TexturedShape)
+
+};
+
+DEFINE_STANDARD_HANDLE (AIS_TexturedShape, AIS_Shape)
+
+#endif // _AIS_TexturedShape_HeaderFile
index 44b3f06..f19a8a5 100755 (executable)
@@ -5,6 +5,8 @@ AIS_LocalContext_1.cxx
 AIS_NListTransient.hxx
 AIS_NListIteratorOfListTransient.hxx
 AIS_NDataMapOfTransientIteratorOfListTransient.hxx
+AIS_TexturedShape.hxx
+AIS_TexturedShape.cxx
 AIS_Triangulation.cdl
 AIS_Triangulation.cxx
 AIS_Dimension.hxx
index 83c2c01..33892f0 100644 (file)
@@ -24,7 +24,8 @@ uses
 
   TypeOfTexture   from Graphic3d,
   NameOfTexture1D from Graphic3d,
-  AsciiString     from TCollection
+  AsciiString     from TCollection,
+  PixMap_Handle   from Image
 
 raises
 
@@ -38,6 +39,9 @@ is
   Initialize (theName : NameOfTexture1D from Graphic3d;
               theType : TypeOfTexture   from Graphic3d);
 
+  Initialize (thePixMap : PixMap_Handle from Image;
+              theType   : TypeOfTexture from Graphic3d);
+
   Name (me) returns NameOfTexture1D from Graphic3d;
   ---Purpose:
   -- Returns the name of the predefined textures or NOT_1D_UNKNOWN
index 7ab73aa..9127eb9 100644 (file)
@@ -47,6 +47,17 @@ Graphic3d_Texture1D::Graphic3d_Texture1D (const Graphic3d_NameOfTexture1D theNOT
           + NameOfTexture_to_FileName[theNOT];
 }
 
+// =======================================================================
+// function : Graphic3d_Texture1D
+// purpose  :
+// =======================================================================
+Graphic3d_Texture1D::Graphic3d_Texture1D (const Handle(Image_PixMap)&   thePixMap,
+                                          const Graphic3d_TypeOfTexture theType)
+: Graphic3d_TextureMap (thePixMap, theType),
+  myName (Graphic3d_NOT_1D_UNKNOWN)
+{
+}
+
 // =======================================================================
 // function : Name
 // purpose  :
index c1dc415..ad7129c 100644 (file)
@@ -24,7 +24,8 @@ inherits Texture1D from Graphic3d
 uses
 
   NameOfTexture1D from Graphic3d,
-  AsciiString     from TCollection
+  AsciiString     from TCollection,
+  PixMap_Handle   from Image
 
 is
 
@@ -34,4 +35,7 @@ is
   Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dmanual from Graphic3d;
   ---Purpose: Create a texture from a predefined texture name set.
 
+  Create (thePixMap : PixMap_Handle from Image) returns mutable Texture1Dmanual from Graphic3d;
+  ---Purpose: Creates a texture from the pixmap.
+
 end Texture1Dmanual;
index 0b03380..31c50c4 100644 (file)
@@ -36,3 +36,13 @@ Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Graphic3d_NameOfText
 {
   //
 }
+
+// =======================================================================
+// function : Graphic3d_Texture1Dmanual
+// purpose  :
+// =======================================================================
+Graphic3d_Texture1Dmanual::Graphic3d_Texture1Dmanual (const Handle(Image_PixMap)& thePixMap)
+: Graphic3d_Texture1D (thePixMap, Graphic3d_TOT_1D)
+{
+  //
+}
index 55d697f..eb7ba4f 100644 (file)
@@ -26,7 +26,8 @@ inherits Texture1D from Graphic3d
 uses
 
   NameOfTexture1D from Graphic3d,
-  AsciiString     from TCollection
+  AsciiString     from TCollection,
+  PixMap_Handle   from Image
 
 is
 
@@ -36,6 +37,9 @@ is
   Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dsegment from Graphic3d;
   ---Purpose: Creates a texture from a predefined texture name set.
 
+  Create (thePixMap : PixMap_Handle from Image) returns mutable Texture1Dsegment from Graphic3d;
+  ---Purpose: Creates a texture from the pixmap.
+
   SetSegment (me : mutable;
               theX1, theY1, theZ1 : ShortReal from Standard;
               theX2, theY2, theZ2 : ShortReal from Standard);
index 96d5ae9..e7aeee5 100644 (file)
@@ -56,6 +56,25 @@ Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTe
                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
 }
 
+// =======================================================================
+// function : Graphic3d_Texture1Dsegment
+// purpose  :
+// =======================================================================
+Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Handle(Image_PixMap)& thePixMap)
+: Graphic3d_Texture1D (thePixMap, Graphic3d_TOT_1D),
+  myX1 (0.0f),
+  myY1 (0.0f),
+  myZ1 (0.0f),
+  myX2 (0.0f),
+  myY2 (0.0f),
+  myZ2 (0.0f)
+{
+  myParams->SetRepeat (Standard_True);
+  myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
+                        Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
+                        Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
+}
+
 // =======================================================================
 // function : SetSegment
 // purpose  :
index c3d4497..87fe18d 100644 (file)
@@ -24,7 +24,8 @@ uses
 
   TypeOfTexture   from Graphic3d,
   NameOfTexture2D from Graphic3d,
-  AsciiString     from TCollection
+  AsciiString     from TCollection,
+  PixMap_Handle   from Image
 
 raises
 
@@ -38,6 +39,9 @@ is
   Initialize (theName : NameOfTexture2D from Graphic3d;
               theType : TypeOfTexture   from Graphic3d);
 
+  Initialize (thePixMap : PixMap_Handle from Image;
+              theType   : TypeOfTexture from Graphic3d);
+
   Name (me) returns NameOfTexture2D from Graphic3d;
   ---Purpose:
   -- Returns the name of the predefined textures or NOT_2D_UNKNOWN
index c5f6786..3d9c38e 100644 (file)
@@ -67,6 +67,17 @@ Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT
           + NameOfTexture_to_FileName[theNOT];
 }
 
+// =======================================================================
+// function : Graphic3d_Texture2D
+// purpose  :
+// =======================================================================
+Graphic3d_Texture2D::Graphic3d_Texture2D (const Handle(Image_PixMap)&    thePixMap,
+                                          const Graphic3d_TypeOfTexture  theType)
+: Graphic3d_TextureMap (thePixMap, theType),
+  myName (Graphic3d_NOT_2D_UNKNOWN)
+{
+}
+
 // =======================================================================
 // function : NumberOfTextures
 // purpose  :
index 8e4d69f..8a24579 100644 (file)
@@ -25,7 +25,8 @@ inherits Texture2D from Graphic3d
 uses
 
   NameOfTexture2D from Graphic3d,
-  AsciiString     from TCollection
+  AsciiString     from TCollection,
+  PixMap_Handle   from Image
 
 is
 
@@ -35,4 +36,7 @@ is
   Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dmanual from Graphic3d;
   ---Purpose: Creates a texture from a predefined texture name set.
 
+  Create (thePixMap : PixMap_Handle from Image) returns mutable Texture2Dmanual from Graphic3d;
+  ---Purpose: Creates a texture from the pixmap.
+
 end Texture2Dmanual;
index c23f4b5..80f5368 100644 (file)
@@ -41,3 +41,15 @@ Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const Graphic3d_NameOfText
   myParams->SetRepeat   (Standard_True);
   myParams->SetFilter   (Graphic3d_TOTF_TRILINEAR);
 }
+
+// =======================================================================
+// function : Graphic3d_Texture2Dmanual
+// purpose  :
+// =======================================================================
+Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const Handle(Image_PixMap)& thePixMap)
+: Graphic3d_Texture2D (thePixMap, Graphic3d_TOT_2D_MIPMAP)
+{
+  myParams->SetModulate (Standard_True);
+  myParams->SetRepeat   (Standard_True);
+  myParams->SetFilter   (Graphic3d_TOTF_TRILINEAR);
+}
index 54155ad..b27d9b1 100644 (file)
@@ -25,7 +25,8 @@ uses
 
   NameOfTexture2D    from Graphic3d,
   NameOfTexturePlane from Graphic3d,
-  AsciiString        from TCollection
+  AsciiString        from TCollection,
+  PixMap_Handle      from Image
 
 is
 
@@ -35,6 +36,9 @@ is
   Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dplane from Graphic3d;
   ---Purpose: Creates a texture from a predefined texture name set.
 
+  Create (thePixMap : PixMap_Handle from Image) returns mutable Texture2Dplane from Graphic3d;
+  ---Purpose: Creates a texture from the pixmap.
+
   SetPlaneS (me : mutable; A, B, C, D : ShortReal from Standard);
   ---Purpose:  Defines the texture projection plane for texture coordinate S
   -- default is <1.0, 0.0, 0.0, 0.0>
index e1b7842..342b8ea 100644 (file)
@@ -48,6 +48,21 @@ Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTextur
                          Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
 }
 
+// =======================================================================
+// function : Graphic3d_Texture2Dplane
+// purpose  :
+// =======================================================================
+Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Handle(Image_PixMap)& thePixMap)
+: Graphic3d_Texture2D (thePixMap, Graphic3d_TOT_2D_MIPMAP)
+{
+  myParams->SetModulate (Standard_True);
+  myParams->SetRepeat   (Standard_True);
+  myParams->SetFilter   (Graphic3d_TOTF_TRILINEAR);
+  myParams->SetGenMode  (Graphic3d_TOTM_OBJECT,
+                         Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
+                         Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
+}
+
 // =======================================================================
 // function : SetPlaneS
 // purpose  :
index dfbdfe0..bfbdb8c 100644 (file)
@@ -25,13 +25,17 @@ uses
   TypeOfTexture from Graphic3d,
   TextureParams from Graphic3d,
   LevelOfTextureAnisotropy from Graphic3d,
-  AsciiString   from TCollection
+  AsciiString   from TCollection,
+  PixMap_Handle from Image
 
 is
 
   Initialize (theFileName : AsciiString from TCollection;
               theType     : TypeOfTexture from Graphic3d);
 
+  Initialize (thePixMap : PixMap_Handle from Image;
+              theType   : TypeOfTexture from Graphic3d);
+
   EnableSmooth (me : mutable);
   ---Level: public
   ---Purpose:
index 4c44e37..55eab0c 100644 (file)
@@ -27,6 +27,16 @@ Graphic3d_TextureMap::Graphic3d_TextureMap (const TCollection_AsciiString& theFi
 {
 }
 
+// =======================================================================
+// function : Graphic3d_TextureMap
+// purpose  :
+// =======================================================================
+Graphic3d_TextureMap::Graphic3d_TextureMap (const Handle(Image_PixMap)&   thePixMap,
+                                            const Graphic3d_TypeOfTexture theType)
+: Graphic3d_TextureRoot (thePixMap, theType)
+{
+}
+
 // =======================================================================
 // function : EnableSmooth
 // purpose  :
index dd47a61..193358d 100644 (file)
@@ -37,6 +37,12 @@ is
   --  Warning: Note that if <FileName> is NULL the texture must be realized
   -- using LoadTexture(image) method.
 
+  Initialize (thePixmap : PixMap_Handle from Image;
+              theType   : TypeOfTexture from Graphic3d);
+  ---Purpose: Creates a texture from pixmap.
+  -- Please note that the implementation expects the image data
+  -- to be in Bottom-Up order (see Image_PixMap::IsTopDown()).
+
   Destroy (me);
   ---C++ : alias ~
 
@@ -85,9 +91,10 @@ is
   ---Level   : Public
   ---Purpose :
   -- This method will be called by graphic driver each time when texture resource should be created.
-  -- Default implementation will dynamically load image from specified path within this method
+  -- Default constructors allow defining the texture source as path to texture image or directly as pixmap.
+  -- If the source is defined as path, then the image will be dynamically loaded when this method is called
   -- (and no copy will be preserved in this class instance).
-  -- Inheritors may dynamically generate the image or return cached instance.
+  -- Inheritors may dynamically generate the image.
   -- Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())!
   -- @return the image for texture.
 
@@ -106,6 +113,7 @@ fields
 
   myParams : TextureParams from Graphic3d is protected;
   myTexId  : AsciiString from TCollection is protected;
+  myPixMap : PixMap_Handle from Image is protected;
   myPath   : Path from OSD is protected;
   myType   : TypeOfTexture from Graphic3d;
 
index 2b7bfd4..bbef8fa 100644 (file)
@@ -91,6 +91,20 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& the
           + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
 }
 
+// =======================================================================
+// function : Graphic3d_TextureRoot
+// purpose  :
+// =======================================================================
+Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)&   thePixMap,
+                                              const Graphic3d_TypeOfTexture theType)
+: myParams (new Graphic3d_TextureParams()),
+  myPixMap (thePixMap),
+  myType   (theType)
+{
+  myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
+          + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
+}
+
 // =======================================================================
 // function : Destroy
 // purpose  :
@@ -124,6 +138,13 @@ const Handle(Graphic3d_TextureParams)& Graphic3d_TextureRoot::GetParams() const
 // =======================================================================
 Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
 {
+  // Case 1: texture source is specified as pixmap
+  if (!myPixMap.IsNull())
+  {
+    return myPixMap;
+  }
+
+  // Case 2: texture source is specified as path
   TCollection_AsciiString aFilePath;
   myPath.SystemName (aFilePath);
   if (aFilePath.IsEmpty())
@@ -146,6 +167,13 @@ Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
 // =======================================================================
 Standard_Boolean Graphic3d_TextureRoot::IsDone() const
 {
+  // Case 1: texture source is specified as pixmap
+  if (!myPixMap.IsNull())
+  {
+    return !myPixMap->IsEmpty();
+  }
+
+  // Case 2: texture source is specified as path
   OSD_File aTextureFile (myPath);
   return aTextureFile.Exists();
 }
index fdab9d1..78f0491 100644 (file)
 */
 class MeshVS_ImageTexture2D : public Graphic3d_Texture2D
 {
-
 public:
 
-  MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg)
-  : Graphic3d_Texture2D ("", Graphic3d_TOT_2D),
-    myImage (theImg)
+  MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg) : Graphic3d_Texture2D (theImg, Graphic3d_TOT_2D)
   {
     myParams->SetModulate (Standard_True);
     myParams->SetFilter   (Graphic3d_TOTF_BILINEAR);
   }
 
-  virtual ~MeshVS_ImageTexture2D()
-  {
-    //
-  }
-
-  virtual Standard_Boolean IsDone() const
-  {
-    return !myImage.IsNull() && !myImage->IsEmpty();
-  }
-
-  virtual Handle(Image_PixMap) GetImage() const
-  {
-    return myImage;
-  }
-
-private:
-
-  Handle(Image_PixMap) myImage;
-
 public:
 
   DEFINE_STANDARD_RTTI(MeshVS_ImageTexture2D)
-
 };
 
 DEFINE_STANDARD_HANDLE    (MeshVS_ImageTexture2D, Graphic3d_Texture2D)
index d4aa3c5..661e057 100755 (executable)
 #include <Draw_Interpretor.hxx>
 #include <DBRep.hxx>
 #include <DrawTrSurf.hxx>
-#include <AIS_InteractiveContext.hxx>
 #include <ViewerTest.hxx>
-#include <AIS_Shape.hxx>
 #include <TopoDS_Shape.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_TexturedShape.hxx>
+#include <Image_PixMap.hxx>
+#include <Image_Color.hxx>
 
 #include <gp_Pnt2d.hxx>
 #include <gp_Ax1.hxx>
@@ -1663,6 +1665,65 @@ struct QABugs_NHandleClass
   }
 };
 
+//=======================================================================
+//function : OCC24622
+//purpose  : The command tests sourcing Image_PixMap to AIS_TexturedShape
+//=======================================================================
+static Standard_Integer OCC24622 (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb != 2)
+  {
+    std::cout << "Usage : " << theArgVec[0] << " texture={1D|2D}";
+    return 1;
+  }
+
+  const Handle(AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
+  if (anAISContext.IsNull())
+  {
+    std::cout << "Please initialize view with \"vinit\".\n";
+    return 1;
+  }
+
+  Handle(Image_PixMap) anImage = new Image_PixMap();
+
+  static const Image_ColorRGB aBitmap[8] = {
+    {255, 0, 0},  {0, 148, 255}, {0, 148, 255}, {255, 94, 0},
+    {255, 121, 0}, {76, 255, 0},  {76, 255, 0}, {255, 202, 0}
+  };
+
+  TCollection_AsciiString aTextureTypeArg (theArgVec[1]);
+  aTextureTypeArg.UpperCase();
+  if (aTextureTypeArg == "1D")
+  {
+    anImage->InitWrapper (Image_PixMap::ImgRGB, (Standard_Byte*)aBitmap, 8, 1);
+  }
+  else if (aTextureTypeArg == "2D")
+  {
+    anImage->InitTrash (Image_PixMap::ImgRGB, 8, 8);
+    Image_PixMapData<Image_ColorRGB>& anImageData = anImage->EditData<Image_ColorRGB>();
+    for (Standard_Integer aRow = 0; aRow < 8; ++aRow)
+    {
+      for (Standard_Integer aCol = 0; aCol < 8; ++aCol)
+      {
+        anImageData.ChangeValue (aRow, aCol) = aBitmap[aRow];
+      }
+    }
+  }
+  else
+  {
+    std::cout << "Please specify type of texture to test {1D|2D}.\n";
+    return 1;
+  }
+
+  TopoDS_Shape aBlankShape = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
+
+  Handle(AIS_TexturedShape) aTexturedShape = new AIS_TexturedShape (aBlankShape);
+  aTexturedShape->SetTexturePixMap (anImage);
+  anAISContext->Display (aTexturedShape, 3, 0);
+
+  return 0;
+}
+
 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
 
@@ -1698,5 +1759,9 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
   theCommands.Add ("OCC24051", "OCC24051", __FILE__, OCC24051, group);
   theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, group);
+  theCommands.Add ("OCC24622", 
+                   "OCC24622 texture={1D|2D}\n"
+                   " Tests sourcing of 1D/2D pixmaps for AIS_TexturedShape.\n",
+                   __FILE__, OCC24622, group);
   return;
 }
diff --git a/tests/bugs/vis/bug24622 b/tests/bugs/vis/bug24622
new file mode 100644 (file)
index 0000000..822e958
--- /dev/null
@@ -0,0 +1,54 @@
+puts "============"
+puts "CR24622"
+puts "============"
+puts ""
+
+##############################################################################
+#  Test for mapping Image_PixMap on AIS_TexturedShape / Graphic3d_TextureRoot
+##############################################################################
+
+set aV1 "Driver1/Viewer1/View1"
+set aV2 "Driver1/Viewer2/View1"
+vinit name=$aV1 l=32 t=32 w=400 h=400
+vinit name=$aV2 l=32 t=32 w=400 h=400
+vactivate $aV1
+vsettexturemode $aV1 2
+vclear
+
+OCC24622 1D
+vtop
+vfit
+
+checkcolor 100 200 0 0.5804 0.949
+
+if { $stat != 1 } {
+  puts "Error : the 1D texture color does not match at px (100, 200)!"
+}
+
+checkcolor 300 200 0.298 1.0 0.0
+
+if { $stat != 1 } {
+  puts "Error : the 1D texture color does not match at px (300, 200)!"
+}
+
+vactivate $aV2
+vsettexturemode $aV2 2
+vclear
+
+OCC24622 2D
+vtop
+vfit
+
+checkcolor 200 100 0 0.5804 0.949
+
+if { $stat != 1 } {
+  puts "Error : the 2D texture color does not match at px (200, 100)!"
+}
+
+checkcolor 200 300 0.298 1.0 0.0
+
+if { $stat != 1 } {
+  puts "Error : the 2D texture color does not match at px (200, 300)!"
+}
+
+set only_screen 1