Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

Shading problem with Mirror in gp_Trsf

Shading problem with Mirror in gp_Trsf
Saretto 2009/10/16 17:21
Hi
I've a problem with the SetMirror() method.
This method in the version void SetMirror(const gp_Ax1 &A1) works!

But I need to use the version : SetMirror (const gp_Ax2 &A2)

For Example :

BRepPrimAPI_MakeBox mkBox(gp_Pnt(100,100,100), 10, 10, 10);
TopoDS_Shape aShape= mkBox.Shape();
gp_Trsf aTrsf;
aTrsf.SetMirror(gp_Ax2(gp_Pnt(0,0,0), gp_Dir(1,0,0)));
TopLoc_Location newLocation(aTrsf);
aShape.Location(newLocation);

The shape takes the transformation (mirroring), but in the Viewer the Shading representation "change color" it becomes darkest (in shadow). See the screenshot :

http://img504.imageshack.us/img504/6135/mirrorproblem.jpg

Saretto

Saretto 2009/11/27 16:51
Nobody has this problem?
Fotis Sioutis 2009/11/27 17:15
Are you using the OCC provided visualization services ?
Saretto 2009/11/30 11:21
"Are you using the OCC provided visualization services ?"

Yes
Fotis Sioutis 2009/11/30 13:04
Then really I have no clue ...

but

your issue reminded me a problem i had in past when i was reading the occ provided mesh in order to pass it to my own renderer.The problem then, was that i did not translate the provided normal with the owner TopoDS_Face transformation.This issue created the exact same side-effect like your case.

Fotis
Saretto 2011/01/31 18:42
UP!

In OCC 6.4 is resolved this issue ????
sergey zaritchny 2011/02/03 10:13
Hi,
Unfortunately I can't reproduce the problem in Draw (in OCCT6.3.0 too).
Used below set of commands with 'mirror' command and
the next visualization in standard AISViewer in shading mode
gives correct result (as you may see it from the attached picture).

box b 100 100 100 10 10 10
copy b b2
tmirror b2 0 0 0 1 0 0
vinit
vdisplay b
# turn on shading mode for the first box 'b'
vdisplay b2
# turn on shading mode for the second box 'b2'
vfit
The resulting shape is attached.
Regards
You have to be logged in to download the attached file
PG 2011/02/03 10:44


Looks fine with me too.
But 'tmirror' command uses the SetMirror function with gp_Ax1 object.
The author wants to use 'gp_Ax2' object.
regards
- PG
sergey zaritchny 2011/02/03 13:29
h'm!
Look, please at the BRepTest_BasicCommands.cxx.
Below is the extraction from the code:
...
if (!strcmp(a[0],"tmirror")) {
if (n < 8) return 1;
T.SetMirror(gp_Ax2(gp_Pnt(atof(a[n-6]),atof(a[n-5]),atof(a[n-4])),
gp_Vec(atof(a[n-3]),atof(a[n-2]),atof(a[n-1]))));
...
}
IMHO it is gp_Ax2.
Regards
Timo 2012/06/11 14:16
The difference is that the Draw command "tmirror" uses BRepBuilderAPI_Transform whereas Saretto in his code just set the location of the shape.

The mirror transformation inverts the normals. Therefore, the shading isn't correct anymore.
Also scaling transformations affect the normals. Therefore, upscaling results in darker lighting, downscaling in lighter Lighting if you just set the shape to a new location.

BRepBuilderAPI_Transform::Perform checks for these cases and uses BRepTools_TrsfModification in these and setting the location of the shape in other cases like e.g. rotations. As far as I understand, BRepTools_TrsfModification creates a transformed copy of the shape and therefore the normals are recalculated.

I don't know where the normals are calculated or if it is possible to force their recalculation.

The same shading problems also occur when you set the transformation of an AIS_InteractiveObject via SetTransformation() to be a scale or mirror transformation after it has been displayed in an AIS_InteractiveContext. This seems to me like a bug. Using BRepBuilderAPI_Transform solves this problem but it is much slower.
A colleague of mine said that you can let OpenGL recalculate the normals automatically by
glEnable(GL_RESCALE_NORMAL);
Would this be a solution for all these problems?
According to http://www.opengl.org/discussion_boards/showthread.php/133406-GL_RESCALE_NORMAL-in-VC GL_RESCALE_NORMAL is contained in OpenGL 1.2.

Kind regards,
Timo
Timo 2012/06/12 13:56
In order to reproduce the mirror problem with AIS_InteractiveObject.SetTransformation you can use the Import Export sample with the following modification:

void CColoredShapes::Display(Handle(AIS_InteractiveContext)& anAIScontext)
{
     for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() )
     {
          Handle(AIS_Shape) ais = new AIS_Shape(iter.Value());
          anAIScontext->SetColor(ais, (Quantity_NameOfColor)m_colorMap.Find(iter.Value()));
          anAIScontext->SetMaterial(ais, Graphic3d_NOM_GOLD, Standard_False);
          anAIScontext->Display(ais, Standard_False);
          
          // modification
          anAIScontext->SetDisplayMode( ais, 1 );
          Handle(Geom_Transformation) t = new Geom_Transformation;
          t->SetMirror( gp_Ax2( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0 ,1 )));
          ais->SetTransformation(t, false, false );
     }
}


When clicking on the "Create box" button, the shading of the created box doesn't work correctly.
Timo 2012/10/09 17:33
I've added

if (myGlContext->core12 != NULL)
{
GLenum err_code;
glGetError();
glEnable(GL_RESCALE_NORMAL);
err_code = glGetError();
if (GL_NO_ERROR != err_code )
{
      throw new std::exception("Could not enable GL_RESCALE_NORMAL. " + err_code);
}
}

at the end of the constructor of OpenGL_Window.
Now, the normals are correct when scaling, but the mirroring-problem remained.
 
 
Latest news
  • New features to enhance the development process
  • Open CASCADE Technology 6.7.1 is available for download!
  • Open CASCADE Technology 6.7.0 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map