View Issue Details

IDProjectCategoryView StatusLast Update
0029823Open CASCADEOCCT:Visualizationpublic2018-10-01 07:34
Reporterkgv Assigned Tobugmaster  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version6.8.0 
Target Version7.4.0Fixed in Version7.4.0 
Summary0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
DescriptionHighlighting by a Bounding Box for an object having Local Transformation results in incorrect results.

The reason is that Bounding Box is defined with pre-multiplied transformation, but renderer includes transformation anyway.

This is a regression after 0024307.

Bounding box GLSL shader (example):
THE_SHADER_IN vec4 occVertex;

uniform vec4 occBBoxCenter;
uniform vec4 occBBoxSize;

void main()
{
  vec4 aPos = vec4(occVertex.xyz * occBBoxSize.xyz + occBBoxCenter.xyz, 1.0);
  gl_Position = occProjectionMatrix * occWorldViewMatrix
              * occModelWorldMatrix * aPos;
}


Bounding box lines:
  Graphic3d_Vec4 aLinesVertices[24];

  const Graphic3d_Vec4 aMin(-0.5f, -0.5f, -0.5f, 1.0f);
  const Graphic3d_Vec4 adX ( 1.0f,  0.0f,  0.0f, 0.0f);
  const Graphic3d_Vec4 adY ( 0.0f,  1.0f,  0.0f, 0.0f);
  const Graphic3d_Vec4 adZ ( 0.0f,  0.0f,  1.0f, 0.0f);

  vec4 anAxisShifts[] = {adX, adY, adZ};
  float aLookup1[] = {0.0f, 1.0f, 0.0f, 1.0f};
  float aLookup2[] = {0.0f, 0.0f, 1.0f, 1.0f};

  int aVertex = 0;
  for (int anAxis = 0; anAxis < 3; ++anAxis)
  {
    for (int j = 0; j < 4; ++j)
    {
      aLinesVertices[aVertex++] = aMin
       + anAxisShifts[(anAxis + 1) % 3] * aLookup1[j]
       + anAxisShifts[(anAxis + 2) % 3] * aLookup2[j];

      aLinesVertices[aVertex++] = aMin + anAxisShifts[anAxis]
       + anAxisShifts[(anAxis + 1) % 3] * aLookup1[j] +
       + anAxisShifts[(anAxis + 2) % 3] * aLookup2[j];
    }
  }
  Handle(OpenGl_VertexBuffer) aVertBuffer = new OpenGl_VertexBuffer();
  aVertBuffer->Init (theCtx, 4, 24, aLinesVertices[0].GetData()));
Steps To Reproduce
pload MODELING VISUALIZATION
vclear
vinit View1
vaxo
psphere s0 1
psphere s1 1
vdisplay -dispMode 1 s0 s1
vsetlocation s1 2 0 0
vfit
vbounding



test v3d glsl phong_pos1 1
vbounding
TagsNo tags attached.
Test case numberv3d/glsl/bndbox1

Attached Files

  • vbounding_spheres_KO.png (56,706 bytes)
  • vbounding_KO.png (27,157 bytes)

Relationships

related to 0028098 closedbugmaster Visualization - errors in tests when using OpenGL ES (ANGLE) 
child of 0024307 closedapn TKOpenGl - efficient culling of large number of presentations 

Activities

kgv

2018-05-29 10:31

developer  

vbounding_spheres_KO.png (56,706 bytes)

kgv

2018-05-29 10:31

developer  

vbounding_KO.png (27,157 bytes)

git

2018-07-02 11:36

administrator   ~0077190

Branch CR29823_1 has been created by mnv.

SHA-1: 8e6ed8ee0a84f7440d11f453b938f19248965f37


Detailed log of new commits:

Author: mnv
Date: Mon Jul 2 11:21:35 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added additional transformation for Bounding Box for compensating renderer transformation.
    Added GLSL program for bounding box drawing and updated bounding box vertices generation algorithm.

kgv

2018-07-02 13:26

developer   ~0077199

+Standard_Boolean OpenGl_ShaderManager::prepareStdProgramBoundBox()

The top header is missing.

+  Handle(OpenGl_ShaderProgram)       myBoundBoxProgram;    //!< standard program for bounding box
+

Please put after myBlitProgram.

+    Handle(OpenGl_VertexBuffer) aVertBuffer = new OpenGl_VertexBuffer();
+    aVertBuffer->Init (aCtx, 4, 24, aLinesVertices[0].GetData());
+    aVertBuffer->BindAttribute (aCtx, Graphic3d_TOA_POS);

This does not make sense to be done at each draw call for each Bounding Box.
Please define single shared OpenGl_VertexBuffer instance (probably bound to ).

     glDisable (GL_LIGHTING);

This is redundant when GLSL program is in effect.

  66   #if !defined(GL_ES_VERSION_2_0)
  67     const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
  68     if (aCtx->core11 == NULL)
  69     {
  70       return;
  71     }

This does not make sense if GLSL program has been implemented.
Please, however, consider providing a fallback for OpenGL 1.1.

+  OpenGl_Vec4 aLinesVertices[24];
+  OpenGl_Vec3 boundBoxCenter;
+  OpenGl_Vec3 boundBoxSize;

This contradicts to OCCT Coding Rules.

+    gp_Trsf curTrsf = theStruct->Transformation()->Trsf();
+    gp_Trsf invTrsf = curTrsf.Inverted();
+    gp_Trsf targetTrsf = curTrsf * invTrsf;
+    theStruct->Transformation()->SetTrsf(targetTrsf);

This is inappropriate modifying a Structure here.

Please also consider possibility removing myHighlightBox field.

git

2018-07-03 14:29

administrator   ~0077233

Branch CR29823_1 has been updated by mnv.

SHA-1: e8480d3ff1c4083769edb0738a511f09a351b04c


Detailed log of new commits:

Author: mnv
Date: Tue Jul 3 14:23:21 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Applyed comments of the last review.
    Updated bounding box drawing procedure according to remove myHighlightBox field.

git

2018-07-03 15:28

administrator   ~0077236

Branch CR29823_1 has been updated by mnv.

SHA-1: 7965ebafd5605bdbcf6043b60963a5cd9c6b115b


Detailed log of new commits:

Author: mnv
Date: Tue Jul 3 15:25:15 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added myBoundBoxVertBuffer to the share resource for correct releasing of the VBO buffer.

mnv

2018-07-03 17:11

developer   ~0077238

http://jenkins-test-11.nnov.opencascade.com:8080/view/CR29823-master-MNV/

git

2018-07-04 10:17

administrator   ~0077254

Branch CR29823_1 has been updated by mnv.

SHA-1: 85de9fcee0b305d3fc559281826e7e6ac940c85b


Detailed log of new commits:

Author: mnv
Date: Wed Jul 4 10:13:08 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added a fallback for OpenGL 1.1 to the OpenGl_Structure::renderBoundingBox function.
    Added a fallback for VBO using.

git

2018-07-04 14:41

administrator   ~0077265

Branch CR29823_2 has been created by mnv.

SHA-1: ad46aabcc14c85d7142646e5a172076eca70fcc0


Detailed log of new commits:

Author: mnv
Date: Mon Jul 2 11:21:35 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added GLSL program for bounding box drawing.
    Updated bounding box vertices generation algorithm.
    Updated bounding box drawing procedure according to remove myHighlightBox field.
    Added myBoundBoxVertBuffer to the share resource for correct releasing of the VBO buffer.
    Added a fallback for OpenGL 1.1 to the OpenGl_Structure::renderBoundingBox function.
    Added a fallback for VBO using.

kgv

2018-07-04 16:45

developer   ~0077269

+  myContext->ShareResource("BoundingBoxVBO", myBoundBoxVertBuffer);

By convention, internal shared resources starts with a class defining them (e.g. "OpenGl_ShaderManager_BndBoxVbo")

+  if (myContext->ToUseVbo())
+  {
+    myBoundBoxVertBuffer = new OpenGl_VertexBuffer();
+  }
+  else
+  {
+    myBoundBoxVertBuffer = new OpenGl_VertexBufferCompat();
+  }

OpenGl_VertexBufferCompat fallback is also expected to be used in case of OpenGl_VertexBuffer initialization failure.

+#include <OpenGl_VertexBuffer.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>

OpenGl_VertexBufferCompat.hxx should be enough.

+  //! Prepare standard GLSL program for bounding box.
+  void initBoundBoxVertices();

Should be moved to private section.

   OpenGl_Context*                    myContext;            //!< OpenGL context
 
+  Handle(OpenGl_VertexBuffer)        myBoundBoxVertBuffer; //!< bounding box vertex buffer

Please move before myContext, right after shader programs list.

+  //! Render the bounding box.
+  void renderBoundingBox (const Handle(OpenGl_Workspace)& theWorkspace) const;

Should be moved to protected section with Standard_EXPORT.

Test case is missing.

git

2018-07-04 17:30

administrator   ~0077270

Branch CR29823_3 has been created by mnv.

SHA-1: 0d02af1883984696ef138d32627422e0cc2cae2e


Detailed log of new commits:

Author: mnv
Date: Mon Jul 2 11:21:35 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added GLSL program for bounding box drawing.
    Updated bounding box vertices generation algorithm.
    Updated bounding box drawing procedure according to remove myHighlightBox field.
    Added myBoundBoxVertBuffer to the share resource for correct releasing of the VBO buffer.
    Added a fallback for OpenGL 1.1 to the OpenGl_Structure::renderBoundingBox function.
    Added a fallback for VBO using.

git

2018-07-04 18:18

administrator   ~0077274

Branch CR29823_4 has been created by mnv.

SHA-1: a43e5a5a85763d0562540268f2c8973f12e45f1d


Detailed log of new commits:

Author: mnv
Date: Mon Jul 2 11:21:35 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Added GLSL program for bounding box drawing.
    Updated bounding box vertices generation algorithm.
    Updated bounding box drawing procedure according to remove myHighlightBox field.
    Added myBoundBoxVertBuffer to the share resource for correct releasing of the VBO buffer.
    Added a fallback for OpenGL 1.1 to the OpenGl_Structure::renderBoundingBox function.
    Added a fallback for VBO using.

mnv

2018-07-05 08:49

developer   ~0077279

Patch is ready for review
http://jenkins-test-11.nnov.opencascade.com:8080/view/CR29823-master-MNV/

git

2018-07-05 10:48

administrator   ~0077280

Branch CR29823_4 has been updated forcibly by mnv.

SHA-1: b38a5368a8b4e6578456beb77a492d13fe461235

git

2018-07-05 22:23

administrator   ~0077296

Branch CR29823_5 has been created by kgv.

SHA-1: 17e9220ceee32ca6bed4e82b0c7906faa9ba9605


Detailed log of new commits:

Author: mnv
Date: Mon Jul 2 11:21:35 2018 +0300

    0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation
    
    Fixed applying object transformation to the bounding box twice within OpenGl_Structure.
    OpenGl_ShaderManager has been extended with GLSL program drawing bounding box.
    OpenGl_Structure does not create extra Groups for drawing bounding box.

kgv

2018-07-06 07:25

developer   ~0077300

Please take the patch.

git

2018-07-06 08:34

administrator   ~0077301

Branch CR29823_5 has been updated forcibly by kgv.

SHA-1: 525f445bdbcd5d4a39fec4c3797eb0556751b9f6

git

2018-07-06 09:44

administrator   ~0077303

Branch CR29823_5 has been updated forcibly by kgv.

SHA-1: 7996dacfccd6fd5c998b5bfc4e25c6588e5499cd

bugmaster

2018-07-06 13:19

administrator   ~0077309

Combination -
OCCT branch : CR29823_5 SHA - 7996dacfccd6fd5c998b5bfc4e25c6588e5499cd
Products branch : master SHA - 8ff715ac468ec83b3308d4e7f390b228b95c965a
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian70-64:
OCCT
Total CPU difference: 17108.830000000078 / 17168.50999999987 [-0.35%]
Products
Total CPU difference: 7495.330000000043 / 7526.93000000002 [-0.42%]
Windows-64-VC10:
OCCT
Total CPU difference: 16836.766727298545 / 16935.000556998602 [-0.58%]
Products
Total CPU difference: 8227.882742499885 / 8215.262261599859 [+0.15%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention

git

2018-07-08 12:00

administrator   ~0077348

Branch CR29823_5 has been deleted by inv.

SHA-1: 7996dacfccd6fd5c998b5bfc4e25c6588e5499cd

git

2018-07-08 12:00

administrator   ~0077350

Branch CR29823_4 has been deleted by inv.

SHA-1: b38a5368a8b4e6578456beb77a492d13fe461235

git

2018-07-08 12:00

administrator   ~0077351

Branch CR29823_3 has been deleted by inv.

SHA-1: 0d02af1883984696ef138d32627422e0cc2cae2e

git

2018-07-08 12:00

administrator   ~0077352

Branch CR29823_2 has been deleted by inv.

SHA-1: ad46aabcc14c85d7142646e5a172076eca70fcc0

git

2018-07-08 12:00

administrator   ~0077355

Branch CR29823_1 has been deleted by inv.

SHA-1: 85de9fcee0b305d3fc559281826e7e6ac940c85b

Related Changesets

occt: master 98b15dbf

2018-07-02 08:21:35

mnv


Committer: bugmaster Details Diff
0029823: Visualization, TKOpenGl - highlighting by Bounding Box mistreats Local Transformation

The problem when object transformation was applied to the bounding box twice has been fixed in OpenGl_Structure.
OpenGl_ShaderManager has been extended with GLSL program drawing bounding box.
OpenGl_Structure does not create extra Groups for drawing bounding box.
Affected Issues
0029823
mod - src/Graphic3d/Graphic3d_CStructure.hxx Diff File
mod - src/Graphic3d/Graphic3d_Structure.cxx Diff File
mod - src/OpenGl/OpenGl_ShaderManager.cxx Diff File
mod - src/OpenGl/OpenGl_ShaderManager.hxx Diff File
mod - src/OpenGl/OpenGl_Structure.cxx Diff File
mod - src/OpenGl/OpenGl_Structure.hxx Diff File
add - tests/v3d/glsl/bndbox1 Diff File

Issue History

Date Modified Username Field Change
2018-05-29 10:31 kgv New Issue
2018-05-29 10:31 kgv Assigned To => kgv
2018-05-29 10:31 kgv File Added: vbounding_spheres_KO.png
2018-05-29 10:31 kgv File Added: vbounding_KO.png
2018-05-29 10:36 kgv Product Version 7.3.0 => 6.8.0
2018-05-29 10:36 kgv Relationship added child of 0024307
2018-05-29 10:37 kgv Description Updated
2018-06-27 12:14 kgv Assigned To kgv => mnv
2018-06-27 12:14 kgv Status new => assigned
2018-06-28 10:25 kgv Description Updated
2018-07-02 11:36 git Note Added: 0077190
2018-07-02 13:12 mnv Assigned To mnv => kgv
2018-07-02 13:12 mnv Status assigned => resolved
2018-07-02 13:26 kgv Note Added: 0077199
2018-07-02 13:26 kgv Assigned To kgv => mnv
2018-07-02 13:26 kgv Status resolved => assigned
2018-07-03 14:29 git Note Added: 0077233
2018-07-03 15:28 git Note Added: 0077236
2018-07-03 17:11 mnv Note Added: 0077238
2018-07-03 17:11 mnv Assigned To mnv => kgv
2018-07-03 17:11 mnv Status assigned => resolved
2018-07-04 10:17 git Note Added: 0077254
2018-07-04 14:41 git Note Added: 0077265
2018-07-04 16:45 kgv Note Added: 0077269
2018-07-04 16:45 kgv Assigned To kgv => mnv
2018-07-04 16:45 kgv Status resolved => assigned
2018-07-04 17:30 git Note Added: 0077270
2018-07-04 18:18 git Note Added: 0077274
2018-07-05 08:49 mnv Note Added: 0077279
2018-07-05 08:49 mnv Assigned To mnv => kgv
2018-07-05 08:49 mnv Status assigned => resolved
2018-07-05 10:48 git Note Added: 0077280
2018-07-05 22:23 git Note Added: 0077296
2018-07-06 07:25 kgv Note Added: 0077300
2018-07-06 07:25 kgv Assigned To kgv => bugmaster
2018-07-06 07:25 kgv Status resolved => reviewed
2018-07-06 08:17 kgv Assigned To bugmaster => kgv
2018-07-06 08:17 kgv Status reviewed => assigned
2018-07-06 08:34 git Note Added: 0077301
2018-07-06 08:34 kgv Assigned To kgv => bugmaster
2018-07-06 08:34 kgv Status assigned => resolved
2018-07-06 08:34 kgv Status resolved => reviewed
2018-07-06 09:44 git Note Added: 0077303
2018-07-06 13:18 bugmaster Test case number => v3d/glsl/bndbox1
2018-07-06 13:19 bugmaster Note Added: 0077309
2018-07-06 13:19 bugmaster Status reviewed => tested
2018-07-08 11:37 bugmaster Changeset attached => occt master 98b15dbf
2018-07-08 11:37 bugmaster Status tested => verified
2018-07-08 11:37 bugmaster Resolution open => fixed
2018-07-08 12:00 git Note Added: 0077348
2018-07-08 12:00 git Note Added: 0077350
2018-07-08 12:00 git Note Added: 0077351
2018-07-08 12:00 git Note Added: 0077352
2018-07-08 12:00 git Note Added: 0077355
2018-10-01 07:34 kgv Relationship added related to 0028098