1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0024622: Add method to AIS_TexturedShape class to assign texture data directly from byte stream

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.
This commit is contained in:
apl 2014-03-06 14:15:39 +04:00 committed by abv
parent d53ae65f65
commit f376ac72de
24 changed files with 588 additions and 437 deletions

View File

@ -146,7 +146,8 @@ uses
StdSelect, StdSelect,
DsgPrs, DsgPrs,
TopTools, TopTools,
Poly Poly,
Image
is is
@ -324,7 +325,7 @@ is
class Triangulation; class Triangulation;
class TexturedShape; imported TexturedShape;
class Drawer; class Drawer;

View File

@ -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;

View File

@ -13,12 +13,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
// Modified: #include <AIS_TexturedShape.hxx>
////////////////////////////////////////////////////////////////////////
#include <AIS_TexturedShape.ixx>
#include <Standard_ErrorHandler.hxx>
#include <AIS_Drawer.hxx> #include <AIS_Drawer.hxx>
#include <AIS_InteractiveContext.hxx> #include <AIS_InteractiveContext.hxx>
@ -33,31 +28,31 @@
#include <Prs3d_Root.hxx> #include <Prs3d_Root.hxx>
#include <Prs3d_ShadingAspect.hxx> #include <Prs3d_ShadingAspect.hxx>
#include <PrsMgr_PresentationManager3d.hxx> #include <PrsMgr_PresentationManager3d.hxx>
#include <Standard_ErrorHandler.hxx>
#include <StdPrs_ShadedShape.hxx> #include <StdPrs_ShadedShape.hxx>
#include <StdPrs_WFDeflectionShape.hxx> #include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_WFShape.hxx> #include <StdPrs_WFShape.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
IMPLEMENT_STANDARD_HANDLE (AIS_TexturedShape, AIS_Shape)
IMPLEMENT_STANDARD_RTTIEXT(AIS_TexturedShape, AIS_Shape)
//======================================================================= //=======================================================================
//function : AIS_TexturedShape //function : AIS_TexturedShape
//purpose : //purpose :
//======================================================================= //=======================================================================
AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape) AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape)
: AIS_Shape (theShape), : AIS_Shape (theShape),
myPredefTexture (Graphic3d_NameOfTexture2D(0)), myPredefTexture (Graphic3d_NameOfTexture2D(0)),
myTextureFile (""), myToMapTexture (Standard_True),
DoRepeat (Standard_True), myModulate (Standard_True),
myURepeat (1.0), myUVOrigin (0.0, 0.0),
myVRepeat (1.0), myIsCustomOrigin (Standard_True),
DoMapTexture (Standard_True), myUVRepeat (1.0, 1.0),
DoSetTextureOrigin (Standard_True), myToRepeat (Standard_True),
myUOrigin (0.0), myUVScale (1.0, 1.0),
myVOrigin (0.0), myToScale (Standard_True),
DoSetTextureScale (Standard_True), myToShowTriangles (Standard_False)
myScaleU (1.0),
myScaleV (1.0),
DoShowTriangles (Standard_False),
myModulate (Standard_True)
{ {
} }
@ -67,16 +62,19 @@ AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape)
//======================================================================= //=======================================================================
void AIS_TexturedShape::SetTextureFileName (const TCollection_AsciiString& theTextureFileName) void AIS_TexturedShape::SetTextureFileName (const TCollection_AsciiString& theTextureFileName)
{ {
myTexturePixMap.Nullify();
if (theTextureFileName.IsIntegerValue()) if (theTextureFileName.IsIntegerValue())
{ {
if (theTextureFileName.IntegerValue() < Graphic3d_Texture2D::NumberOfTextures() const Standard_Integer aValue = theTextureFileName.IntegerValue();
&& theTextureFileName.IntegerValue() >= 0) if (aValue < Graphic3d_Texture2D::NumberOfTextures()
&& aValue >= 0)
{ {
myPredefTexture = Graphic3d_NameOfTexture2D (theTextureFileName.IntegerValue()); myPredefTexture = Graphic3d_NameOfTexture2D (aValue);
} }
else else
{ {
std::cout << "Texture " << theTextureFileName << " doesn't exist \n"; std::cout << "Texture " << theTextureFileName << " doesn't exist\n";
std::cout << "Using Texture 0 instead ...\n"; std::cout << "Using Texture 0 instead ...\n";
myPredefTexture = Graphic3d_NameOfTexture2D (0); myPredefTexture = Graphic3d_NameOfTexture2D (0);
} }
@ -85,22 +83,32 @@ void AIS_TexturedShape::SetTextureFileName (const TCollection_AsciiString& theTe
else else
{ {
myTextureFile = theTextureFileName; 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 //function : SetTextureRepeat
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theRepeatYN, void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theToRepeat,
const Standard_Real theURepeat, const Standard_Real theURepeat,
const Standard_Real theVRepeat) const Standard_Real theVRepeat)
{ {
DoRepeat = theRepeatYN; myToRepeat = theToRepeat;
myURepeat = theURepeat; myUVRepeat.SetCoord (theURepeat, theVRepeat);
myVRepeat = theVRepeat;
} }
//======================================================================= //=======================================================================
@ -110,7 +118,7 @@ void AIS_TexturedShape::SetTextureRepeat (const Standard_Boolean theRepeatYN,
void AIS_TexturedShape::SetTextureMapOn() void AIS_TexturedShape::SetTextureMapOn()
{ {
DoMapTexture = Standard_True; myToMapTexture = Standard_True;
} }
//======================================================================= //=======================================================================
@ -120,7 +128,7 @@ void AIS_TexturedShape::SetTextureMapOn()
void AIS_TexturedShape::SetTextureMapOff() void AIS_TexturedShape::SetTextureMapOff()
{ {
DoMapTexture = Standard_False; myToMapTexture = Standard_False;
} }
//======================================================================= //=======================================================================
@ -128,13 +136,12 @@ void AIS_TexturedShape::SetTextureMapOff()
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean toSetTextureOriginYN, void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean theToSetTextureOrigin,
const Standard_Real theUOrigin, const Standard_Real theUOrigin,
const Standard_Real theVOrigin) const Standard_Real theVOrigin)
{ {
DoSetTextureOrigin = toSetTextureOriginYN; myIsCustomOrigin = theToSetTextureOrigin;
myUOrigin = theUOrigin; myUVOrigin.SetCoord (theUOrigin, theVOrigin);
myVOrigin = theVOrigin;
} }
//======================================================================= //=======================================================================
@ -142,13 +149,12 @@ void AIS_TexturedShape::SetTextureOrigin (const Standard_Boolean toSetTextureOri
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_TexturedShape::SetTextureScale (const Standard_Boolean toSetTextureScaleYN, void AIS_TexturedShape::SetTextureScale (const Standard_Boolean theToSetTextureScale,
const Standard_Real theScaleU, const Standard_Real theScaleU,
const Standard_Real theScaleV) const Standard_Real theScaleV)
{ {
DoSetTextureScale = toSetTextureScaleYN; myToScale = theToSetTextureScale;
myScaleU = theScaleU; myUVScale.SetCoord (theScaleU, theScaleV);
myScaleV = theScaleV;
} }
//======================================================================= //=======================================================================
@ -156,9 +162,9 @@ void AIS_TexturedShape::SetTextureScale (const Standard_Boolean toSetTextureScal
//purpose : //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; Prs3d_ShadingAspect aDummy;
myAspect = aDummy.Aspect(); myAspect = aDummy.Aspect();
Handle(Prs3d_Presentation) aPrs = Presentation(); Handle(Prs3d_Presentation) aPrs = Presentation();
if (!DoMapTexture) if (!myToMapTexture)
{ {
myAspect->SetTextureMapOff(); myAspect->SetTextureMapOff();
return; return;
} }
if (myPredefTexture != -1) if (!myTexturePixMap.IsNull())
mytexture = new Graphic3d_Texture2Dmanual (myPredefTexture); {
myTexture = new Graphic3d_Texture2Dmanual (myTexturePixMap);
}
else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN)
{
myTexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
}
else else
mytexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString()); {
myTexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
}
myAspect->SetTextureMapOn(); myAspect->SetTextureMapOn();
myAspect->SetTextureMap (mytexture); myAspect->SetTextureMap (myTexture);
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; return;
} }
if (DoShowTriangles) if (myToShowTriangles)
myAspect->SetEdgeOn(); myAspect->SetEdgeOn();
else else
myAspect->SetEdgeOff(); myAspect->SetEdgeOff();
@ -224,7 +238,7 @@ void AIS_TexturedShape::UpdateAttributes()
//purpose : //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 Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) const Standard_Integer theMode)
{ {
@ -257,12 +271,12 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
switch (theMode) switch (theMode)
{ {
case 0: // Wireframe case AIS_WireFrame:
{ {
StdPrs_WFDeflectionShape::Add (thePrs, myshape, myDrawer); StdPrs_WFDeflectionShape::Add (thePrs, myshape, myDrawer);
break; break;
} }
case 1: // Shading case AIS_Shaded:
{ {
Standard_Real prevangle; Standard_Real prevangle;
Standard_Real newangle; Standard_Real newangle;
@ -298,7 +312,6 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
} }
break; break;
} }
case 2: // Bounding box case 2: // Bounding box
{ {
if (IsInfinite()) if (IsInfinite())
@ -311,10 +324,9 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
} }
break; break;
} }
case 3: // texture mapping on triangulation case 3: // texture mapping on triangulation
{ {
BRepTools::Clean (myshape); BRepTools::Clean (myshape);
BRepTools::Update (myshape); BRepTools::Update (myshape);
{ {
@ -330,48 +342,56 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
myAspect->SetPolygonOffsets(aMode, aFactor, aUnits); myAspect->SetPolygonOffsets(aMode, aFactor, aUnits);
} }
} }
if (!DoMapTexture) if (!myToMapTexture)
{ {
myAspect->SetTextureMapOff(); myAspect->SetTextureMapOff();
return; return;
} }
myAspect->SetTextureMapOn(); myAspect->SetTextureMapOn();
if (myPredefTexture != -1) if (!myTexturePixMap.IsNull())
mytexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
else
mytexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
if (!mytexture->IsDone())
{ {
std::cout << "An error occured while building texture \n"; myTexture = new Graphic3d_Texture2Dmanual (myTexturePixMap);
}
else if (myPredefTexture != Graphic3d_NOT_2D_UNKNOWN)
{
myTexture = new Graphic3d_Texture2Dmanual (myPredefTexture);
}
else
{
myTexture = new Graphic3d_Texture2Dmanual (myTextureFile.ToCString());
}
if (!myTexture->IsDone())
{
std::cout << "An error occurred while building texture \n";
return; return;
} }
if (myModulate) if (myModulate)
mytexture->EnableModulate(); myTexture->EnableModulate();
else else
mytexture->DisableModulate(); myTexture->DisableModulate();
myAspect->SetTextureMap (mytexture); myAspect->SetTextureMap (myTexture);
if (DoShowTriangles) if (myToShowTriangles)
myAspect->SetEdgeOn(); myAspect->SetEdgeOn();
else else
myAspect->SetEdgeOff(); myAspect->SetEdgeOff();
if (DoRepeat) if (myToRepeat)
mytexture->EnableRepeat(); myTexture->EnableRepeat();
else else
mytexture->DisableRepeat(); myTexture->DisableRepeat();
const gp_Pnt2d aUVOrigin (myUOrigin, myVOrigin);
const gp_Pnt2d aUVRepeat (myURepeat, myVRepeat);
const gp_Pnt2d aUVScale (myScaleU, myScaleV);
try try
{ {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
StdPrs_ShadedShape::Add (thePrs, myshape, myDrawer, 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 // within primitive arrays - object should be in one group of primitives
Prs3d_Root::CurrentGroup (thePrs)->SetGroupPrimitivesAspect (myAspect); 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;
}

View File

@ -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

View File

@ -5,6 +5,8 @@ AIS_LocalContext_1.cxx
AIS_NListTransient.hxx AIS_NListTransient.hxx
AIS_NListIteratorOfListTransient.hxx AIS_NListIteratorOfListTransient.hxx
AIS_NDataMapOfTransientIteratorOfListTransient.hxx AIS_NDataMapOfTransientIteratorOfListTransient.hxx
AIS_TexturedShape.hxx
AIS_TexturedShape.cxx
AIS_Triangulation.cdl AIS_Triangulation.cdl
AIS_Triangulation.cxx AIS_Triangulation.cxx
AIS_Dimension.hxx AIS_Dimension.hxx

View File

@ -24,7 +24,8 @@ uses
TypeOfTexture from Graphic3d, TypeOfTexture from Graphic3d,
NameOfTexture1D from Graphic3d, NameOfTexture1D from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
raises raises
@ -38,6 +39,9 @@ is
Initialize (theName : NameOfTexture1D from Graphic3d; Initialize (theName : NameOfTexture1D from Graphic3d;
theType : TypeOfTexture from Graphic3d); theType : TypeOfTexture from Graphic3d);
Initialize (thePixMap : PixMap_Handle from Image;
theType : TypeOfTexture from Graphic3d);
Name (me) returns NameOfTexture1D from Graphic3d; Name (me) returns NameOfTexture1D from Graphic3d;
---Purpose: ---Purpose:
-- Returns the name of the predefined textures or NOT_1D_UNKNOWN -- Returns the name of the predefined textures or NOT_1D_UNKNOWN

View File

@ -47,6 +47,17 @@ Graphic3d_Texture1D::Graphic3d_Texture1D (const Graphic3d_NameOfTexture1D theNOT
+ NameOfTexture_to_FileName[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 // function : Name
// purpose : // purpose :

View File

@ -24,7 +24,8 @@ inherits Texture1D from Graphic3d
uses uses
NameOfTexture1D from Graphic3d, NameOfTexture1D from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
is is
@ -34,4 +35,7 @@ is
Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dmanual from Graphic3d; Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dmanual from Graphic3d;
---Purpose: Create a texture from a predefined texture name set. ---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; end Texture1Dmanual;

View 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)
{
//
}

View File

@ -26,7 +26,8 @@ inherits Texture1D from Graphic3d
uses uses
NameOfTexture1D from Graphic3d, NameOfTexture1D from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
is is
@ -36,6 +37,9 @@ is
Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dsegment from Graphic3d; Create (theNOT : NameOfTexture1D from Graphic3d) returns mutable Texture1Dsegment from Graphic3d;
---Purpose: Creates a texture from a predefined texture name set. ---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; SetSegment (me : mutable;
theX1, theY1, theZ1 : ShortReal from Standard; theX1, theY1, theZ1 : ShortReal from Standard;
theX2, theY2, theZ2 : ShortReal from Standard); theX2, theY2, theZ2 : ShortReal from Standard);

View File

@ -56,6 +56,25 @@ Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTe
Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); 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 // function : SetSegment
// purpose : // purpose :

View File

@ -24,7 +24,8 @@ uses
TypeOfTexture from Graphic3d, TypeOfTexture from Graphic3d,
NameOfTexture2D from Graphic3d, NameOfTexture2D from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
raises raises
@ -38,6 +39,9 @@ is
Initialize (theName : NameOfTexture2D from Graphic3d; Initialize (theName : NameOfTexture2D from Graphic3d;
theType : TypeOfTexture from Graphic3d); theType : TypeOfTexture from Graphic3d);
Initialize (thePixMap : PixMap_Handle from Image;
theType : TypeOfTexture from Graphic3d);
Name (me) returns NameOfTexture2D from Graphic3d; Name (me) returns NameOfTexture2D from Graphic3d;
---Purpose: ---Purpose:
-- Returns the name of the predefined textures or NOT_2D_UNKNOWN -- Returns the name of the predefined textures or NOT_2D_UNKNOWN

View File

@ -67,6 +67,17 @@ Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT
+ NameOfTexture_to_FileName[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 // function : NumberOfTextures
// purpose : // purpose :

View File

@ -25,7 +25,8 @@ inherits Texture2D from Graphic3d
uses uses
NameOfTexture2D from Graphic3d, NameOfTexture2D from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
is is
@ -35,4 +36,7 @@ is
Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dmanual from Graphic3d; Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dmanual from Graphic3d;
---Purpose: Creates a texture from a predefined texture name set. ---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; end Texture2Dmanual;

View File

@ -41,3 +41,15 @@ Graphic3d_Texture2Dmanual::Graphic3d_Texture2Dmanual (const Graphic3d_NameOfText
myParams->SetRepeat (Standard_True); myParams->SetRepeat (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_TRILINEAR); 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);
}

View File

@ -25,7 +25,8 @@ uses
NameOfTexture2D from Graphic3d, NameOfTexture2D from Graphic3d,
NameOfTexturePlane from Graphic3d, NameOfTexturePlane from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
is is
@ -35,6 +36,9 @@ is
Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dplane from Graphic3d; Create (theNOT : NameOfTexture2D from Graphic3d) returns mutable Texture2Dplane from Graphic3d;
---Purpose: Creates a texture from a predefined texture name set. ---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); SetPlaneS (me : mutable; A, B, C, D : ShortReal from Standard);
---Purpose: Defines the texture projection plane for texture coordinate S ---Purpose: Defines the texture projection plane for texture coordinate S
-- default is <1.0, 0.0, 0.0, 0.0> -- default is <1.0, 0.0, 0.0, 0.0>

View File

@ -48,6 +48,21 @@ Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTextur
Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); 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 // function : SetPlaneS
// purpose : // purpose :

View File

@ -25,13 +25,17 @@ uses
TypeOfTexture from Graphic3d, TypeOfTexture from Graphic3d,
TextureParams from Graphic3d, TextureParams from Graphic3d,
LevelOfTextureAnisotropy from Graphic3d, LevelOfTextureAnisotropy from Graphic3d,
AsciiString from TCollection AsciiString from TCollection,
PixMap_Handle from Image
is is
Initialize (theFileName : AsciiString from TCollection; Initialize (theFileName : AsciiString from TCollection;
theType : TypeOfTexture from Graphic3d); theType : TypeOfTexture from Graphic3d);
Initialize (thePixMap : PixMap_Handle from Image;
theType : TypeOfTexture from Graphic3d);
EnableSmooth (me : mutable); EnableSmooth (me : mutable);
---Level: public ---Level: public
---Purpose: ---Purpose:

View 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 // function : EnableSmooth
// purpose : // purpose :

View File

@ -37,6 +37,12 @@ is
-- Warning: Note that if <FileName> is NULL the texture must be realized -- Warning: Note that if <FileName> is NULL the texture must be realized
-- using LoadTexture(image) method. -- 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); Destroy (me);
---C++ : alias ~ ---C++ : alias ~
@ -85,9 +91,10 @@ is
---Level : Public ---Level : Public
---Purpose : ---Purpose :
-- This method will be called by graphic driver each time when texture resource should be created. -- 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). -- (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())! -- Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())!
-- @return the image for texture. -- @return the image for texture.
@ -106,6 +113,7 @@ fields
myParams : TextureParams from Graphic3d is protected; myParams : TextureParams from Graphic3d is protected;
myTexId : AsciiString from TCollection is protected; myTexId : AsciiString from TCollection is protected;
myPixMap : PixMap_Handle from Image is protected;
myPath : Path from OSD is protected; myPath : Path from OSD is protected;
myType : TypeOfTexture from Graphic3d; myType : TypeOfTexture from Graphic3d;

View File

@ -91,6 +91,20 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& the
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER)); + 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 // function : Destroy
// purpose : // purpose :
@ -124,6 +138,13 @@ const Handle(Graphic3d_TextureParams)& Graphic3d_TextureRoot::GetParams() const
// ======================================================================= // =======================================================================
Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() 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; TCollection_AsciiString aFilePath;
myPath.SystemName (aFilePath); myPath.SystemName (aFilePath);
if (aFilePath.IsEmpty()) if (aFilePath.IsEmpty())
@ -146,6 +167,13 @@ Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
// ======================================================================= // =======================================================================
Standard_Boolean Graphic3d_TextureRoot::IsDone() 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); OSD_File aTextureFile (myPath);
return aTextureFile.Exists(); return aTextureFile.Exists();
} }

View File

@ -62,40 +62,17 @@
*/ */
class MeshVS_ImageTexture2D : public Graphic3d_Texture2D class MeshVS_ImageTexture2D : public Graphic3d_Texture2D
{ {
public: public:
MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg) MeshVS_ImageTexture2D (const Handle(Image_PixMap)& theImg) : Graphic3d_Texture2D (theImg, Graphic3d_TOT_2D)
: Graphic3d_Texture2D ("", Graphic3d_TOT_2D),
myImage (theImg)
{ {
myParams->SetModulate (Standard_True); myParams->SetModulate (Standard_True);
myParams->SetFilter (Graphic3d_TOTF_BILINEAR); 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: public:
DEFINE_STANDARD_RTTI(MeshVS_ImageTexture2D) DEFINE_STANDARD_RTTI(MeshVS_ImageTexture2D)
}; };
DEFINE_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D) DEFINE_STANDARD_HANDLE (MeshVS_ImageTexture2D, Graphic3d_Texture2D)

View File

@ -18,10 +18,12 @@
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <DBRep.hxx> #include <DBRep.hxx>
#include <DrawTrSurf.hxx> #include <DrawTrSurf.hxx>
#include <AIS_InteractiveContext.hxx>
#include <ViewerTest.hxx> #include <ViewerTest.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_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_Pnt2d.hxx>
#include <gp_Ax1.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) { void QABugs::Commands_19(Draw_Interpretor& theCommands) {
const char *group = "QABugs"; 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 ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
theCommands.Add ("OCC24051", "OCC24051", __FILE__, OCC24051, group); theCommands.Add ("OCC24051", "OCC24051", __FILE__, OCC24051, group);
theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, 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; return;
} }

54
tests/bugs/vis/bug24622 Normal file
View File

@ -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