return 0;
}
+//==============================================================================
+//function : VConvert
+//purpose :
+//==============================================================================
+
+static int VConvert (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+{
+ // get the active view
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ std::cerr << "No active view. Please call vinit.\n";
+ return 1;
+ }
+
+ enum { Model, Ray, View, Window, Grid } aMode = Model;
+
+ // access coordinate arguments
+ TColStd_SequenceOfReal aCoord;
+ Standard_Integer anArgIdx = 1;
+ for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
+ {
+ TCollection_AsciiString anArg (theArgVec[anArgIdx]);
+ if (!anArg.IsRealValue())
+ {
+ break;
+ }
+ aCoord.Append (anArg.RealValue());
+ }
+
+ // non-numeric argument too early
+ if (aCoord.IsEmpty())
+ {
+ std::cerr << "Error: wrong number of arguments! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+
+ // collect all other arguments and options
+ for (; anArgIdx < theArgNb; ++anArgIdx)
+ {
+ TCollection_AsciiString anArg (theArgVec[anArgIdx]);
+ anArg.LowerCase();
+ if (anArg == "window") aMode = Window;
+ else if (anArg == "view") aMode = View;
+ else if (anArg == "grid") aMode = Grid;
+ else if (anArg == "ray") aMode = Ray;
+ else
+ {
+ std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+ }
+
+ // complete input checks
+ if ((aCoord.Length() == 1 && theArgNb > 3) ||
+ (aCoord.Length() == 2 && theArgNb > 4) ||
+ (aCoord.Length() == 3 && theArgNb > 5))
+ {
+ std::cerr << "Error: wrong number of arguments! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+
+ Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+ Standard_Integer aXYp[2] = {0, 0};
+
+ // convert one-dimensional coordinate
+ if (aCoord.Length() == 1)
+ {
+ switch (aMode)
+ {
+ case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
+ case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
+ default:
+ std::cerr << "Error: wrong arguments! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+ }
+
+ // convert 2D coordinates from projection or view reference space
+ if (aCoord.Length() == 2)
+ {
+ switch (aMode)
+ {
+ case Model :
+ aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
+ theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
+ return 0;
+
+ case View :
+ aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
+ theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
+ return 0;
+
+ case Window :
+ aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
+ theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
+ return 0;
+
+ case Grid :
+ aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
+ aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
+ theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
+ return 0;
+
+ case Ray :
+ aView->ConvertWithProj ((Standard_Integer) aCoord (1),
+ (Standard_Integer) aCoord (2),
+ aXYZ[0], aXYZ[1], aXYZ[2],
+ aXYZ[3], aXYZ[4], aXYZ[5]);
+ theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
+ return 0;
+
+ default:
+ std::cerr << "Error: wrong arguments! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+ }
+
+ // convert 3D coordinates from view reference space
+ else if (aCoord.Length() == 3)
+ {
+ switch (aMode)
+ {
+ case Window :
+ aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
+ theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
+ return 0;
+
+ case Grid :
+ aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
+ theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
+ return 0;
+
+ default:
+ std::cerr << "Error: wrong arguments! See usage:\n";
+ theDI.PrintHelp (theArgVec[0]);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
//==============================================================================
//function : VFps
//purpose :
" : Mode - rectangular or circular"
" : Type - lines or points",
__FILE__, VGrid, group);
+ theCommands.Add ("vconvert",
+ "vconvert v [Mode={window|view}]"
+ "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
+ "\n\t\t: vconvert x y z [Mode={window|grid}]"
+ "\n\t\t: window - convert to window coordinates, pixels"
+ "\n\t\t: view - convert to view projection plane"
+ "\n\t\t: grid - convert to model coordinates, given on grid"
+ "\n\t\t: ray - convert projection ray to model coordiantes"
+ "\n\t\t: - vconvert v window : convert view to window;"
+ "\n\t\t: - vconvert v view : convert window to view;"
+ "\n\t\t: - vconvert x y window : convert view to window;"
+ "\n\t\t: - vconvert x y view : convert window to view;"
+ "\n\t\t: - vconvert x y : convert window to model;"
+ "\n\t\t: - vconvert x y grid : convert window to model using grid;"
+ "\n\t\t: - vconvert x y ray : convert window projection line to model;"
+ "\n\t\t: - vconvert x y z window : convert model to window;"
+ "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
+ "\n\t\t: Converts the given coordinates to window/view/model space.",
+ __FILE__, VConvert, group);
theCommands.Add ("vfps",
"vfps [framesNb=100] : estimate average frame rate for active view",
__FILE__, VFps, group);
--- /dev/null
+puts "============"
+puts "CR25671"
+puts "============"
+puts ""
+#######################################################################
+# V3d_View::Convert doesn't work as expected in GRID active mode.
+#######################################################################
+pload VISUALIZATION
+vinit View1 w=400 h=400
+
+# 1. Synthetic case for detection with AIS_InteractiveContext::MoveTo
+set detect_x 197
+set detect_y 229
+
+set cylinder_r 5
+set cylinder_h 10
+set cylinder_xyz {100 0 0}
+
+vgrid c p -10 0 5 5 45
+pcylinder c $cylinder_r $cylinder_h
+ttranslate c {*}$cylinder_xyz
+vdisplay c
+vfit
+vmoveto $detect_x $detect_y
+checkcolor $detect_x $detect_y 0 1 1
+
+if { $stat != 1 } {
+ puts "Error : Detection does not work correctly with activated grid."
+}
+
+vgrid off
+vremove -all
+
+# 2.1 Quick test of coordinate conversion commands
+set view_scale 2.5
+set view_proj {0 1 0}
+set view_up {0 0 1}
+set view_eye {0.5 100.5 0.5}
+set view_at {0.5 0.5 0.5}
+set view_znear 0
+set view_zfar 150
+
+vviewparams -scale $view_scale -eye {*}$view_eye -at {*}$view_at -proj {*}$view_proj -up {*}$view_up
+vzrange $view_znear $view_zfar
+
+set vconvert_1_view [vconvert 1.0 view]
+set vconvert_1_win [vconvert 1.0 window]
+set vconvert_00_00_win [vconvert 0.0 0.0 window]
+set vconvert_200_200_view [vconvert 200 200 view]
+set vconvert_05_05_ray [vconvert 0.5 0.5 ray]
+set vconvert_200_200_model [vconvert 200 200]
+set vconvert_05_100_05_win [vconvert 0.5 100 0.5 window]
+
+checkreal "vconvert 1.0 view, view 1" [lindex $vconvert_1_view 2] 1.0 1e-7 0.0
+checkreal "vconvert 1.0 window, view 1" [lindex $vconvert_1_win 2] 1.0 1e-7 0.0
+checkreal "vconvert 0.0 0.0 window, view 1, Xp" [lindex $vconvert_00_00_win 2] 200.0 1.0 0.0
+checkreal "vconvert 0.0 0.0 window, view 1, Yp" [lindex $vconvert_00_00_win 3] 200.0 1.0 0.0
+checkreal "vconvert 200 200 view, view 1, Xv" [lindex $vconvert_200_200_view 2] 0.0 1e-7 0.0
+checkreal "vconvert 200 200 view, view 1, Yv" [lindex $vconvert_200_200_view 3] 0.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 1, DX" [lindex $vconvert_05_05_ray 2] 0.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 1, DY" [lindex $vconvert_05_05_ray 3] -1.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 1, DZ" [lindex $vconvert_05_05_ray 4] 0.0 1e-7 0.0
+checkreal "vconvert 200 200, view 1, X" [lindex $vconvert_200_200_model 2] 0.5 1.0 0.0
+checkreal "vconvert 200 200, view 1, Y" [lindex $vconvert_200_200_model 3] 100.5 1.0 0.0
+checkreal "vconvert 200 200, view 1, Z" [lindex $vconvert_200_200_model 4] -0.5 1.0 0.0
+checkreal "vconvert 0.5 100 0.5 window, view 1, Xp" [lindex $vconvert_05_100_05_win 2] 200.0 1.0 0.0
+checkreal "vconvert 0.5 100 0.5 window, view 1, Yp" [lindex $vconvert_05_100_05_win 3] 199.0 1.0 0.0
+
+# 2.2 Quick test of coordinate conversion commands
+vgrid r 10 10 1 1 45
+
+set view_scale 49.504950495049506
+set view_proj {0 0 1}
+set view_up {0 1 0}
+set view_eye {25 5 125}
+set view_at {25 5 45}
+set view_znear 0
+set view_zfar 150
+
+vviewparams -scale $view_scale -eye {*}$view_eye -at {*}$view_at -proj {*}$view_proj -up {*}$view_up
+vzrange $view_znear $view_zfar
+
+set vconvert_1_view [vconvert 1.0 view]
+set vconvert_1_win [vconvert 1.0 window]
+set vconvert_00_00_win [vconvert 0.0 0.0 window]
+set vconvert_200_200_view [vconvert 200 200 view]
+set vconvert_05_05_ray [vconvert 0.5 0.5 ray]
+set vconvert_200_200_model [vconvert 200 200]
+set vconvert_200_200_grid [vconvert 200 200 grid]
+set vconvert_25_5_35_win [vconvert 25.0 4.94 35.0 window]
+set vconvert_25_5_35_grid [vconvert 25.0 4.94 35.0 grid]
+
+checkreal "vconvert 1.0 view, view 2" [lindex $vconvert_1_view 2] 0.05 0.05 0.0
+checkreal "vconvert 1.0 window, view 2" [lindex $vconvert_1_win 2] 19.0 0.05 0.0
+checkreal "vconvert 0.0 0.0 window, view 2, Xp" [lindex $vconvert_00_00_win 2] 200.0 1.0 0.0
+checkreal "vconvert 0.0 0.0 window, view 2, Yp" [lindex $vconvert_00_00_win 3] 200.0 1.0 0.0
+checkreal "vconvert 200 200 view, view 2, Xv" [lindex $vconvert_200_200_view 2] 0.0 1e-7 0.0
+checkreal "vconvert 200 200 view, view 2, Yv" [lindex $vconvert_200_200_view 3] 0.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 2, DX" [lindex $vconvert_05_05_ray 2] 0.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 2, DY" [lindex $vconvert_05_05_ray 3] 0.0 1e-7 0.0
+checkreal "vconvert 0.5 0.5 ray, view 2, DZ" [lindex $vconvert_05_05_ray 4] -1.0 1e-7 0.0
+checkreal "vconvert 200 200, view 2, X" [lindex $vconvert_200_200_model 2] 25.0 0.05 0.0
+checkreal "vconvert 200 200, view 2, Y" [lindex $vconvert_200_200_model 3] 4.95 0.05 0.0
+checkreal "vconvert 200 200, view 2, Z" [lindex $vconvert_200_200_model 4] 125.0 0.05 0.0
+checkreal "vconvert 200 200 grid, view 2, X" [lindex $vconvert_200_200_grid 2] 25.486 0.05 0.0
+checkreal "vconvert 200 200 grid, view 2, Y" [lindex $vconvert_200_200_grid 3] 4.856 0.05 0.0
+checkreal "vconvert 200 200 grid, view 2, Z" [lindex $vconvert_200_200_grid 4] 0.0 0.05 0.0
+checkreal "vconvert 0.5 100 0.5 window, view 2, Xp" [lindex $vconvert_25_5_35_win 2] 200.0 1.0 0.0
+checkreal "vconvert 0.5 100 0.5 window, view 2, Yp" [lindex $vconvert_25_5_35_win 3] 200.0 1.0 0.0
+checkreal "vconvert 25 4.94 35 grid, view 2, X" [lindex $vconvert_25_5_35_grid 2] 25.486 0.05 0.0
+checkreal "vconvert 25 4.94 35 grid, view 2, Y" [lindex $vconvert_25_5_35_grid 3] 4.856 0.05 0.0
+checkreal "vconvert 25 4.94 35 grid, view 2, Z" [lindex $vconvert_25_5_35_grid 4] 0.0 0.05 0.0
+
+# do not save any image
+set only_screen 0