DiscussionsIssue archiveOCCT:Visualization

Archived issue #0024413

Visualization - get rid of projection shift from orthographic camera definition

Open CASCADEOCCT:Visualizationclosed19 public notes

Search issues

Description

There are several issues remain in camera functionality which should be fixed:
- eliminate projection shift conception;
- update NIS_View::FitAll3d();
- improve Znear,Zfar management.

Additional information

The projection shift concept was removed. The reference system of the view is now located at the center of screen, in consistence with definition rules of a camera. There is no more Center property of V3d_View, which was originally used to specify shift of projection matrix and to slide reference system of the view along the screen.

This improvement has effect on panning and turning behavior of V3d_View. The panning is now performed by sliding location of V3d_View: At, Eye. The turning around reference system of the view is done as usually, except that the reference system is now located in center of the view.

Fit all operation was modified in order to support perspective projection. The low-level implementation of the operation is now used by both V3d_View and NIS_View. The core behavior of fit all is now unified for these classes, however the principal differences are kept untouched.

There are several changes introduced to Graphic3d_Camera. The internal data structures of the camera is based on Standard_Real data types to avoid redundant application-level conversions and precision errors. The transformation matrices are now can be evaluated both for Standard_Real and Standard_ShortReal value types. The ZNear and ZFar planes can be both negative or positive for orthographic camera projection, providing a trade-off between camera distance and range of ZNear, ZFar in order to reduce difference of exponents of values composing the orientation matrix - to avoid calculation errors. The negative values can be specified to avoid Z-clipping if the reference system of camera goes inside of the model when decreasing camera distance.

The auto z fit mode, since now, has a parameter defining Z-range margin (the one which is usually passed as argument to ZFitAll() method). The V3d_View SetAutoZFitMode(), AutoZFitScaleFactor(), ZFitAll() methods deals with the new parameter.

The code of Select3D_Projector class has been revised. It supports both orientation and projection transformation matrices, which can be naturally set for the projector. The definition of projector was revised in StdSelect_ViewerSelector3d: perspective and orthographic projection parameters are handled properly. Orthographic projector is based only on direction of projection - no more Center property. This makes possible to avoid unnecessary re-projection of sensitives while panning, zooming or moving along the projection ray of the view. These operations do not affect the orthographic projection.

List of changes:

V3d_View

- Center() has been removed. SetCenter() method now changes relative location of the center of screen.
- Panning now translates At, Eye position of the view along the view plane.
- SetViewingVolume() has been removed. The same modifications to viewing volume can be done via camera of the view (Camera()).
- Duplicating method Zoom (CurrX, CurrY) has been removed. The method Zoom (FromX, FromY, ToX, ToY) should be used instead.
- SetAutoZFitMode(), AutoZFitScaleFactor(), ZFitAll() deal with new parameter: Z-range margin.
- Turn() method now performs rotation around view reference system, which is located at center of the screen (around screen axes). Center() has no effect anymore. To produce similar rotation to the previous one, the effect of Center() can be introduced by rotating view around a point with Rotate() method.

Graphic3d_Camera

- ProjectionShift(), SetProjectionShift() are removed.
- SetZNear(), SetZFar() have been replaced by unified SetZRange() method. ZNear, ZFar can be negative for orthographic camera.
- BeginUpdate(), EndUpdate() methods have been replaced by matrix lazy-computation approach. There is no necessity in these methods anymore.
- WindowLimit() method is removed - is redundant. The method had the same meaning as ViewDimensions(), summed up with ProjectionShift().
- ViewDimension(), AxialScale() - type of argument is changed from gp_Pnt to gp_XYZ.

Select3D_Projector

- Added methods to defined both view-transformation and projection-transformation matrices.
- The projector now contains constant projection / orientation state. Previously it was possible to pass handle on the view, so the Project() method was giving projection results for actual view projection. However, the same handle was not used for other projector methods: Transform(), Transformation().
- SetView() instead of saving reference on the passed view, captures current state of its projection / orientation matrices.

Porting notes:

It might be necessary to revise code of the application, which deals with Center() method of V3d_View. The Center() was used to pan V3d view by virtually moving center of the screen with respect to projection ray passed through Eye and At points. There is no more need to derive the panning from the Center parameter in order to get camera-like position of eye and look at coordinates. The Eye(), At() now returns these coordinates directly. When porting code dealing with Center(), the Eye() and At() could be adjusted instead. The behavior of Turn(), Panning(), Pan() view operations is changed. Please refer to "List of changes" for more details.

Public activity

19 archived notes

Participants are labeled by their role within this record.

01Commenter 1
Projection shift and its role.

The reported problem of projection shift concept related to projection "precision" issues. In current implementation, the projection shift - is a translation of OpenGL projection (!) matrix along its horizontal or vertical axis.

The idea which lead to use of the projection shift concept is appeared during porting of V3d_View behavior on current camera classes. The V3d_View has several peculiarities related to representation of view projection in user-interface terms. The view defines projection with view referential point "At", projection of view "Proj", position of spectacular "Eye" and the translation, called "Center" against line passed through "At" point trough "Proj" vector. The translation is done in view plane. In general, this translation stands for panning. Another role that center plays - is a reference when converting model space point coordinates into view plane with "Convert" methods. E.g. user can define a referential axis with {"At", "Proj"} and perform panning of view, ensuring that coordinates produced by "Convert" for the same model space point will not change with panning - the user can "Convert" the point once, and then set center to it from any panning. The "Center" also applies to window-to-view mapping term of V3d_View. There are several inconsistencies:
1) Panning for perspective view is unacceptable.
2) Such idea contradicts with common sense of projection definition - normally line from "at"
to "eye" point lie in center of the screen. Here, being panned, the center of screen moves
away from that line.
3) There are two methods SetCenter - one defining center as pixel coordinates along screen,
another one as {u,v} panning coordinates against "At" point. The difference is that pixel
coordinates are relative to screen and slide in space with panning, while the {u,v} coordinates
do not change during panning.
4) Precision problems related to point conversion with applied "Center" panning.

The problem with projection shift can be resolved by moving this concept from projection matrix (and hence OpenGL operations) to pure "Convert" operations performed at level of V3d_View.

Removing projection shift idea completely - unification with cameras.

Another approach is to make the interface of V3d_View more clear by making agreement that "Center" - is always the center of the screen. Thus, the method returning value of center is not necessary anymore, and the methods for setting the center SetCenter(pixel), SetCenter(u,v) are to relocate the center of the screen to the new coordinates given as pixels or {u,v} relative to current view projection.

In this approach the panning should translate "at" and "eye" point so as they are always correspond to center of the screen. The "Convert" methods will return {u=0,v=0} for model points lying in center of the screen - the referential axis is now bound to the center. This could be more practical as the user could set center of view to any desired point from model space by simply specifying the Center to {u,v} coordinates obtained by "Converting" the point.

This approach gives the following "effect" for V3d_View interface and behavior:
1) At, Eye are correspond to center of the screen;
2) SetCenter methods relocate center of the screen against current projection.
3) Center method is removed;
4) SetViewingVolume (is it used?) method is removed. Scale/ZNear/ZFar can be changed directly as camera properties.
5) "Window coordiantes" now calculated relatively to the center of screen - during porting it might be necessary to check that window coordinates for "fit all" operations are computed properly (if "Convert", "Project" are used for this purpose - there are changes should be required).
6) Convert, ConvertToGrid, ConvertWithProj are calculated relatively to center of the screen.

02Commenter 2
Dear apl,
I think unification is preferred. It will facilitate development and support of camera system greatly.
03Commenter 3
Difference in Z-Near, Z-Far management and Z-fit operations has nothing to do with "camera projection shift", hence these points to be treated in dedicated issue (from its description) #0024287
04Commenter 4
Dear kgv,

Could you please review branch CR24413_1?

It contains all of the improvements all together:
- Removed projection shift concept, and "center" property of V3d_View.
- Revised AutoZFit mode of V3d_View to add control for avoiding clipping of "infinite" structures.
- Modified V3d_View, NIS_View FitAll method such that perspective projection is now taken into account.
- Improved Select3D_Projector to work with natural view-transformation, view-projection matrices.
- Adjusted code of StdSelect_ViewerSelector3d to new approach of panning, without "center". Improved the class to avoid unnecessary re-projections of sensitives on panning, depth panning and zooming of orthographic view. For perspective view, the re-projection is done for every change of major parameters.
05Author
Dear Commenter 1,

please test the patch.
06Commenter 6
Anton, please consider changing syntax of the command vviewparams so as to avoid necessity to use quotes for grouping arguments; this is somehow rarely used and difficult to guess. It is better to use approach widely adopted in Tcl: have a key followed by list of arguments.

For instance, instead of:

vviewparams scale=${scale} "proj=${proj_X} ${proj_Y} ${proj_Z}" "up=${up_X} ${up_Y} ${up_Z}" "at=${at_X} ${at_Y} ${at_Z}"

you would have:

vviewparams -scale ${scale} -proj ${proj_X} ${proj_Y} ${proj_Z} -up ${up_X} ${up_Y} ${up_Z} -at ${at_X} ${at_Y} ${at_Z}
07Commenter 7
Dear Commenter 1,

Branch CR24413_1 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]

Number of compiler warnings:

occt component :
Linux: 33 (29 on master)
Windows: 0 (0 on master)

New additional warnings on Linux platform:
http://jenkins-test-02.nnov.opencascade.com:8080/user/mnt/my-views/view/A_mnt_warnings/job/mnt-CR24413_1-master_build_occt_linux/1/warnings16Result/package.1928144792/
Select3D_Projector.cxx:159, GNU C Compiler 4 (gcc), Priority: Normal
when initialized here
Select3D_Projector.cxx:175, GNU C Compiler 4 (gcc), Priority: Normal
when initialized here

products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)

Regressions/Differences:
http://occt-tests/CR24413-1-master-occt/Windows-32-VC9/bugs/vis/buc60688.html
bugs vis(004) buc60688: FAILED

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 382547108 / 383237256
Total CPU difference: 66006.19000000019 / 42570.57999999976

Testing on Windows:
Total MEMORY difference: 429393188 / 429022388
Total CPU difference: 30921.953125 / 33299.015625

There are following differences in images found by testdiff.
http://occt-tests/CR24413-1-master-occt/Debian60-64/diff-Debian60-64.html
http://occt-tests/CR24413-1-master-occt/Windows-32-VC9/diff-Windows-32-VC9.html
IMAGE bugs modalg_5(010) bug24012: bug24012_Driver1_Viewer1_View1.png differs
08Commenter 8
There are following differences in testdiff images found and analyzed:

Issues:
- IMAGE mesh advanced_shading A5 (issue with fit all - fixed)
- IMAGE bugs modalg_4 bug22383 (issue with fit all - fixed)
- IMAGE bugs modalg_5 bug24012 (different orientation - fixed)

Set of perf tests:
- IMAGE perf multi_mesh_shading A4
- IMAGE perf multi_mesh_shading A1
- IMAGE perf multi_mesh_shading A2
- IMAGE perf single_mesh_wireframe A4
- IMAGE perf single_mesh_wireframe A1
- IMAGE perf single_mesh_wireframe A2
- IMAGE perf single_mesh_shading A4
- IMAGE perf single_mesh_shading A1
- IMAGE perf single_mesh_shading A2
- IMAGE perf single_mesh_shrink A4
- IMAGE perf single_mesh_shrink A4
- IMAGE perf single_mesh_shrink A2
- IMAGE perf multi_mesh_wireframe A4
- IMAGE perf multi_mesh_wireframe A1
- IMAGE perf multi_mesh_wireframe A2
- IMAGE perf multi_mesh_shrink A4
- IMAGE perf multi_mesh_shrink A1
- IMAGE perf multi_mesh_shrink A2
Minor differences result of new behavior of V3d_View::Turn operation - it now corresponds to rotation around center of view reference, which is center of view.

Set of perspective test cases:
IMAGE bugs vis bug349
IMAGE bugs vis bug349
IMAGE bugs vis bug349_1
IMAGE bugs vis bug280_3
IMAGE bugs vis bug280_2
IMAGE bugs vis bug24001
IMAGE bugs vis bug24001
IMAGE bugs vis bug24001
IMAGE bugs vis bug24001
The results are OK - improved "fit all" for perspective projection

09Commenter 9
Dear kgv,

Branch CR24413_2 is ready for review (CR24413_1 contains history of recent changes).
10Author
Please test new patch.
11Commenter 11
Dear Commenter 1,

Branch CR24413_2 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]

Number of compiler warnings:

occt component :
Linux: 29 (29 on master)
Windows: 0 (0 on master)

products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)

Regressions/Differences:
http://occt-tests/CR24413-2-master-occt/Debian60-64/summary.html
http://occt-tests/CR24413-2-master-occt/Windows-32-VC9/summary.html
3rdparty export A2, A3, A4, A5, A6, A7
demo samples raytrace
v3d raytrace bug24130, connected, plastic

http://jenkins-test-02.nnov.opencascade.com:8080/user/mnt/my-views/view/CR24413_2/job/mnt-CR24413_2-master_products_tests_linux_start/label=Debian60-64,tests_group=emesh,tests_subgroup=002/4/HTML_Report/?
http://jenkins-test-02.nnov.opencascade.com:8080/user/mnt/my-views/view/CR24413_2/job/mnt-CR24413_2-master_products_tests_windows_start/label=windows_test,tests_group=emesh,tests_subgroup=002/1/HTML_Report/?
emesh bugs(002) bug24034_2

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 382699744 / 381959196
Total CPU difference: 40524.84000000025 / 45114.180000000015

Testing on Windows:
Total MEMORY difference: 429565744 / 428499952
Total CPU difference: 34295.90625 / 34630.3125

There are follwing differences in images found by testdiff.
http://occt-tests/CR24413-2-master-occt/Debian60-64/diff-Debian60-64.html
http://occt-tests/CR24413-2-master-occt/Windows-32-VC9/diff-Windows-32-VC9.html
IMAGE bugs vis bug61: bug61_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_8: bug281_8_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug22149: bug22149_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug23747_1: bug23747_1_with_envmap.png differs
IMAGE bugs vis bug281_9: bug281_9_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug21171_1: bug21171_1_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug21171_3: bug21171_3_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_7: bug281_7_Driver1_Viewer1_View1.png differs
IMAGE bugs vis buc60818: buc60818_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_1: bug281_11_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_1: bug281_12_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_1: bug281_13_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_1: bug281_1_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_1: bug281_10_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug349: bug349_1_Driver1_Viewer1_View1_new.png differs
IMAGE bugs vis bug349: bug349_Driver1_Viewer1_View1_new.png differs
IMAGE bugs vis bug349_1: bug349_1_Driver1_Viewer1_View1_new.png differs
IMAGE bugs vis bug281_10: bug281_10_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_13: bug281_13_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_6: bug281_6_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_5: bug281_5_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_3: bug281_3_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug280_3: bug280_3_Driver1_Viewer1_View1_new.png differs
IMAGE bugs vis bug280_2: bug280_2_Driver1_Viewer1_View1_new.png differs
IMAGE bugs vis bug281_11: bug281_11_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug24001: bug24001_persp.png differs
IMAGE bugs vis bug24001: bug24001_afterSwitch.png differs
IMAGE bugs vis bug24001: bug24001_stereoR.png differs
IMAGE bugs vis bug24001: bug24001_stereoL.png differs
IMAGE bugs vis bug281_2: bug281_2_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_12: bug281_12_Driver1_Viewer1_View1.png differs
IMAGE bugs vis bug281_4: bug281_4_Driver1_Viewer1_View1.png differs

12Commenter 12
Dear kgv,

Could you please review branch CR24413_3 (CR24413_2 contains recent history)?

The failed products test cases were also updated: CR24413 in products repository.
13Author
Dear Commenter 1,

please test CR24413_4 branch.
14Commenter 14
Dear Commenter 1,

Branch CR24413_4 and CR24413 from GIT products master was compiled on Linux and Windows platforms and tested.
[revision removed]
[revision removed]

Number of compiler warnings:

occt component :
Linux: 29 (29 on master)
Windows: 0 (0 on master)

products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)

Regressions/Differences:
On Linux, for example

http://occt-tests/CR24413-4-CR24413-occt/Debian60-64/mesh/advanced_shading/A1.html
...
vinit
DRAWEXE: symbol lookup error: /dn61/LocalWOK/wok_entities/LOC/dev/CR24413-4-CR24413-occt/lib/libTKOpenGl.so.0: undefined symbol: _ZNK16Graphic3d_Camera16UpdateProjectionIfEERNS_17TransformMatricesIT_EES4_

15Commenter 15
Dear kgv,

Could you please review corrections in CR24413_4?
16Author
No remarks, please test CR24413_4.
17Commenter 17
Dear Commenter 1,

Branch CR24413_4 and CR24413 from GIT products master was compiled on Linux and Windows platforms and tested.
[revision removed]
[revision removed]

Number of compiler warnings:

occt component :
Linux: 29 (29 on master)
Windows: 0 (0 on master)

products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)

Regressions/Differences:
No regressions/differences

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 382900272 / 382826772
Total CPU difference: 41606.2500000001 / 52926.14000000003

Testing on Windows:
Total MEMORY difference: 429147708 / 428893460
Total CPU difference: 31610.640625 / 32992.765625

There are following differences in images found by testdiff.
http://occt-tests/CR24413-4-CR24413-occt/Windows-32-VC9/diff-Windows-32-VC9.html
IMAGE v3d glsl phong_views: phong_views_2.png differs

18Commenter 18
Dear mkv,

The difference in image for second view is more probably related to the issue with sharing shader state between different views. The same image can be obtained by adding vrepaint or vfit before dumping second view. The bug for the shader issue is reported as #0024687, and the problem, I guess, should be analyzed and fixed within that context. There is no point to resolve the problem within scope of #0024413.

Please proceed.

19Commenter 19
OK.
Branches CR24413_4 and CR24413 are TESTED.

Related records