root/OpenSceneGraph/trunk/examples/osgunittests/osgunittests.cpp @ 8921

Revision 8921, 22.7 kB (checked in by robert, 6 years ago)

Added read-threads <numThreads> command line and read thread test back end

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* OpenSceneGraph example, osgunittests.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#include <osg/ArgumentParser>
20#include <osg/ApplicationUsage>
21
22#include <osg/Vec3>
23#include <osg/Matrix>
24#include <osg/Polytope>
25#include <osg/Timer>
26#include <osg/io_utils>
27
28#include <OpenThreads/Thread>
29
30#include "UnitTestFramework.h"
31#include "performance.h"
32#include "MultiThreadRead.h"
33
34#include <iostream>
35
36void testFrustum(double left,double right,double bottom,double top,double zNear,double zFar)
37{
38    osg::Matrix f;
39    f.makeFrustum(left,right,bottom,top,zNear,zFar);
40
41    double c_left=0;
42    double c_right=0;
43    double c_top=0;
44    double c_bottom=0;
45    double c_zNear=0;
46    double c_zFar=0;
47   
48   
49    std::cout << "testFrustum"<<f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar)<<std::endl;
50    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
51    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
52
53    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
54    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
55
56    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
57    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
58   
59    std::cout << std::endl;
60}
61
62void testOrtho(double left,double right,double bottom,double top,double zNear,double zFar)
63{
64    osg::Matrix f;
65    f.makeOrtho(left,right,bottom,top,zNear,zFar);
66
67    double c_left=0;
68    double c_right=0;
69    double c_top=0;
70    double c_bottom=0;
71    double c_zNear=0;
72    double c_zFar=0;
73
74    std::cout << "testOrtho "<< f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar) << std::endl;
75    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
76    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
77
78    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
79    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
80
81    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
82    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
83   
84    std::cout << std::endl;
85}
86
87void testPerspective(double fovy,double aspect,double zNear,double zFar)
88{
89    osg::Matrix f;
90    f.makePerspective(fovy,aspect,zNear,zFar);
91
92    double c_fovy=0;
93    double c_aspect=0;
94    double c_zNear=0;
95    double c_zFar=0;
96
97    std::cout << "testPerspective "<< f.getPerspective(c_fovy,c_aspect,c_zNear,c_zFar) << std::endl;
98    std::cout << "  fovy = "<<fovy<<" compute "<<c_fovy<<std::endl;
99    std::cout << "  aspect = "<<aspect<<" compute "<<c_aspect<<std::endl;
100
101    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
102    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
103   
104    std::cout << std::endl;
105}
106
107void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
108{
109    osg::Matrix mv;
110    mv.makeLookAt(eye,center,up);
111   
112    osg::Vec3 c_eye,c_center,c_up;
113    mv.getLookAt(c_eye,c_center,c_up);
114   
115    std::cout << "testLookAt"<<std::endl;
116    std::cout << "  eye "<<eye<< " compute "<<c_eye<<std::endl;
117    std::cout << "  center "<<center<< " compute "<<c_center<<std::endl;
118    std::cout << "  up "<<up<< " compute "<<c_up<<std::endl;
119   
120    std::cout << std::endl;
121   
122}
123
124
125void testMatrixInvert(const osg::Matrix& matrix)
126{
127    //Invert it twice using the two inversion functions and view the results
128    osg::notify(osg::NOTICE)<<"testMatrixInvert("<<std::endl;
129    osg::notify(osg::NOTICE)<<matrix<<std::endl;
130    osg::notify(osg::NOTICE)<<")"<<std::endl;
131
132    osg::Matrix invM1_0;
133    invM1_0.invert(matrix);
134    osg::notify(osg::NOTICE)<<"Matrix::invert"<<std::endl;
135    osg::notify(osg::NOTICE)<<invM1_0<<std::endl;
136    osg::Matrix default_result = matrix*invM1_0;
137    osg::notify(osg::NOTICE)<<"matrix * invert="<<std::endl;
138    osg::notify(osg::NOTICE)<<default_result<<std::endl;;
139
140}
141
142void sizeOfTest()
143{
144  std::cout<<"sizeof(bool)=="<<sizeof(bool)<<std::endl;
145  std::cout<<"sizeof(char)=="<<sizeof(char)<<std::endl;
146  std::cout<<"sizeof(short)=="<<sizeof(short)<<std::endl;
147  std::cout<<"sizeof(short int)=="<<sizeof(short int)<<std::endl;
148  std::cout<<"sizeof(int)=="<<sizeof(int)<<std::endl;
149  std::cout<<"sizeof(long)=="<<sizeof(long)<<std::endl;
150  std::cout<<"sizeof(long int)=="<<sizeof(long int)<<std::endl;
151
152#if defined(_MSC_VER)
153  // long long isn't supported on VS6.0...
154  std::cout<<"sizeof(__int64)=="<<sizeof(__int64)<<std::endl;
155#else
156  std::cout<<"sizeof(long long)=="<<sizeof(long long)<<std::endl;
157#endif
158  std::cout<<"sizeof(float)=="<<sizeof(float)<<std::endl;
159  std::cout<<"sizeof(double)=="<<sizeof(double)<<std::endl;
160
161  std::cout<<"sizeof(std::istream::pos_type)=="<<sizeof(std::istream::pos_type)<<std::endl;
162  std::cout<<"sizeof(std::istream::off_type)=="<<sizeof(std::istream::off_type)<<std::endl;
163  std::cout<<"sizeof(OpenThreads::Mutex)=="<<sizeof(OpenThreads::Mutex)<<std::endl;
164
165  std::cout<<"sizeof(std::string)=="<<sizeof(std::string)<<std::endl;
166
167}
168
169/// Exercise the Matrix.getRotate function.
170/// Compare the output of:
171///  q1 * q2
172/// versus
173///  (mat(q1)*mat(q2)*scale).getRotate()
174/// for a range of rotations
175void testGetQuatFromMatrix(const osg::Vec3d& scale)
176{
177   
178    // Options
179   
180    // acceptable error range
181    double eps=1e-6;
182
183    // scale matrix
184    // To not test with scale, use 1,1,1
185    // Not sure if 0's or negative values are acceptable
186    osg::Matrixd scalemat;
187    scalemat.makeScale(scale);
188   
189    // range of rotations
190#if 1
191    // wide range
192    double rol1start = 0.0;
193    double rol1stop = 360.0;
194    double rol1step = 20.0;
195
196    double pit1start = 0.0;
197    double pit1stop = 90.0;
198    double pit1step = 20.0;
199
200    double yaw1start = 0.0;
201    double yaw1stop = 360.0;
202    double yaw1step = 20.0;
203
204    double rol2start = 0.0;
205    double rol2stop = 360.0;
206    double rol2step = 20.0;
207
208    double pit2start = 0.0;
209    double pit2stop = 90.0;
210    double pit2step = 20.0;
211
212    double yaw2start = 0.0;
213    double yaw2stop = 360.0;
214    double yaw2step = 20.0;
215#else
216    // focussed range
217    double rol1start = 0.0;
218    double rol1stop = 0.0;
219    double rol1step = 0.1;
220
221    double pit1start = 0.0;
222    double pit1stop = 5.0;
223    double pit1step = 5.0;
224
225    double yaw1start = 89.0;
226    double yaw1stop = 91.0;
227    double yaw1step = 0.1;
228
229    double rol2start = 0.0;
230    double rol2stop = 0.0;
231    double rol2step = 0.1;
232
233    double pit2start = 0.0;
234    double pit2stop = 0.0;
235    double pit2step = 0.1;
236
237    double yaw2start = 89.0;
238    double yaw2stop = 91.0;
239    double yaw2step = 0.1;
240#endif
241
242    std::cout << std::endl << "Starting testGetQuatFromMatrix, it can take a while ..." << std::endl;
243
244    osg::Timer_t tstart, tstop;
245    tstart = osg::Timer::instance()->tick();
246    int count=0;
247    for (double rol1 = rol1start; rol1 <= rol1stop; rol1 += rol1step) {
248        for (double pit1 = pit1start; pit1 <= pit1stop; pit1 += pit1step) {
249            for (double yaw1 = yaw1start; yaw1 <= yaw1stop; yaw1 += yaw1step) {
250                for (double rol2 = rol2start; rol2 <= rol2stop; rol2 += rol2step) {
251                    for (double pit2 = pit2start; pit2 <= pit2stop; pit2 += pit2step) {
252                        for (double yaw2 = yaw2start; yaw2 <= yaw2stop; yaw2 += yaw2step)
253                        {
254                            count++;
255                            // create two quats based on the roll, pitch and yaw values
256                            osg::Quat rot_quat1 =
257                            osg::Quat(osg::DegreesToRadians(rol1),osg::Vec3d(1,0,0),
258                                  osg::DegreesToRadians(pit1),osg::Vec3d(0,1,0),
259                                  osg::DegreesToRadians(yaw1),osg::Vec3d(0,0,1));
260
261                            osg::Quat rot_quat2 =
262                            osg::Quat(osg::DegreesToRadians(rol2),osg::Vec3d(1,0,0),
263                                  osg::DegreesToRadians(pit2),osg::Vec3d(0,1,0),
264                                  osg::DegreesToRadians(yaw2),osg::Vec3d(0,0,1));
265
266                            // create an output quat using quaternion math
267                            osg::Quat out_quat1;
268                            out_quat1 = rot_quat2 * rot_quat1;
269
270                            // create two matrices based on the input quats
271                            osg::Matrixd mat1,mat2;
272                            mat1.makeRotate(rot_quat1);
273                            mat2.makeRotate(rot_quat2);
274
275                            // create an output quat by matrix multiplication and getRotate
276                            osg::Matrixd out_mat;
277                            out_mat = mat2 * mat1;
278                            // add matrix scale for even more nastiness
279                            out_mat = out_mat * scalemat;
280                            osg::Quat out_quat2;
281                            out_quat2 = out_mat.getRotate();
282
283                            // If the quaternion W is <0, then we should reflect
284                            // to get it into the positive W.
285                            // Unfortunately, when W is very small (close to 0), the sign
286                            // does not really make sense because of precision problems
287                            // and the reflection might not work.
288                            if(out_quat1.w()<0) out_quat1 = out_quat1 * -1.0;
289                            if(out_quat2.w()<0) out_quat2 = out_quat2 * -1.0;
290
291                            // if the output quat length is not one
292                            // or if the components do not match,
293                            // something is amiss
294
295                            bool componentsOK = false;
296                            if ( ((fabs(out_quat1.x()-out_quat2.x())) < eps) &&
297                                 ((fabs(out_quat1.y()-out_quat2.y())) < eps) &&
298                                 ((fabs(out_quat1.z()-out_quat2.z())) < eps) &&
299                                 ((fabs(out_quat1.w()-out_quat2.w())) < eps) )
300                                    {
301                                componentsOK = true;
302                            }
303                            // We should also test for q = -q which is valid, so reflect
304                            // one quat.
305                            out_quat2 = out_quat2 * -1.0;
306                            if ( ((fabs(out_quat1.x()-out_quat2.x())) < eps) &&
307                                 ((fabs(out_quat1.y()-out_quat2.y())) < eps) &&
308                                 ((fabs(out_quat1.z()-out_quat2.z())) < eps) &&
309                                 ((fabs(out_quat1.w()-out_quat2.w())) < eps) )
310                            {
311                                componentsOK = true;
312                            }
313
314                            bool lengthOK = false;
315                            if (fabs(1.0-out_quat2.length()) < eps)
316                            {
317                                lengthOK = true;
318                            }
319
320                            if (!lengthOK || !componentsOK)
321                            {
322                                std::cout << "testGetQuatFromMatrix problem at: \n"
323                                      << " r1=" << rol1
324                                      << " p1=" << pit1
325                                      << " y1=" << yaw1
326                                      << " r2=" << rol2
327                                      << " p2=" << pit2
328                                      << " y2=" << yaw2 << "\n";
329                                std::cout << "quats:        " << out_quat1 << " length: " << out_quat1.length() << "\n";
330                                std::cout << "mats and get: " << out_quat2 << " length: " << out_quat2.length() << "\n\n";
331                            }
332                        }
333                    }
334                }
335            }
336        }
337    }
338    tstop = osg::Timer::instance()->tick();
339    double duration = osg::Timer::instance()->delta_s(tstart,tstop);
340    std::cout << "Time for testGetQuatFromMatrix with " << count << " iterations: " << duration << std::endl << std::endl;
341}
342
343void testQuatRotate(const osg::Vec3d& from, const osg::Vec3d& to)
344{
345    osg::Quat q_nicolas;
346    q_nicolas.makeRotate(from,to);
347   
348    osg::Quat q_original;
349    q_original.makeRotate_original(from,to);
350   
351    std::cout<<"osg::Quat::makeRotate("<<from<<", "<<to<<")"<<std::endl;
352    std::cout<<"  q_nicolas = "<<q_nicolas<<std::endl;
353    std::cout<<"  q_original = "<<q_original<<std::endl;
354    std::cout<<"  from * M4x4(q_nicolas) = "<<from * osg::Matrixd::rotate(q_nicolas)<<std::endl;
355    std::cout<<"  from * M4x4(q_original) = "<<from * osg::Matrixd::rotate(q_original)<<std::endl;
356}
357
358void testQuat(const osg::Vec3d& quat_scale)
359{
360    osg::Quat q1;
361    q1.makeRotate(osg::DegreesToRadians(30.0),0.0f,0.0f,1.0f);
362
363    osg::Quat q2;
364    q2.makeRotate(osg::DegreesToRadians(133.0),0.0f,1.0f,1.0f);
365
366    osg::Quat q1_2 = q1*q2;
367    osg::Quat q2_1 = q2*q1;
368
369    osg::Matrix m1 = osg::Matrix::rotate(q1);
370    osg::Matrix m2 = osg::Matrix::rotate(q2);
371   
372    osg::Matrix m1_2 = m1*m2;
373    osg::Matrix m2_1 = m2*m1;
374   
375    osg::Quat qm1_2;
376    qm1_2.set(m1_2);
377   
378    osg::Quat qm2_1;
379    qm2_1.set(m2_1);
380   
381    std::cout<<"q1*q2 = "<<q1_2<<std::endl;
382    std::cout<<"q2*q1 = "<<q2_1<<std::endl;
383    std::cout<<"m1*m2 = "<<qm1_2<<std::endl;
384    std::cout<<"m2*m1 = "<<qm2_1<<std::endl;
385
386
387    testQuatRotate(osg::Vec3d(1.0,0.0,0.0),osg::Vec3d(0.0,1.0,0.0));
388    testQuatRotate(osg::Vec3d(0.0,1.0,0.0),osg::Vec3d(1.0,0.0,0.0));
389    testQuatRotate(osg::Vec3d(0.0,0.0,1.0),osg::Vec3d(0.0,1.0,0.0));
390    testQuatRotate(osg::Vec3d(1.0,1.0,1.0),osg::Vec3d(1.0,0.0,0.0));
391    testQuatRotate(osg::Vec3d(1.0,0.0,0.0),osg::Vec3d(1.0,0.0,0.0));
392    testQuatRotate(osg::Vec3d(1.0,0.0,0.0),osg::Vec3d(-1.0,0.0,0.0));
393    testQuatRotate(osg::Vec3d(-1.0,0.0,0.0),osg::Vec3d(1.0,0.0,0.0));
394    testQuatRotate(osg::Vec3d(0.0,1.0,0.0),osg::Vec3d(0.0,-1.0,0.0));
395    testQuatRotate(osg::Vec3d(0.0,-1.0,0.0),osg::Vec3d(0.0,1.0,0.0));
396    testQuatRotate(osg::Vec3d(0.0,0.0,1.0),osg::Vec3d(0.0,0.0,-1.0));
397    testQuatRotate(osg::Vec3d(0.0,0.0,-1.0),osg::Vec3d(0.0,0.0,1.0));
398
399    // Test a range of rotations
400    testGetQuatFromMatrix(quat_scale);
401
402    // This is a specific test case for a matrix containing scale and rotation
403    osg::Matrix matrix(0.5, 0.0, 0.0, 0.0,
404                       0.0, 0.5, 0.0, 0.0,
405                       0.0, 0.0, 0.5, 0.0,
406                       1.0, 1.0, 1.0, 1.0);
407                       
408    osg::Quat quat;
409    matrix.get(quat);
410   
411    osg::notify(osg::NOTICE)<<"Matrix = "<<matrix<<"rotation = "<<quat<<", expected quat = (0,0,0,1)"<<std::endl;
412}
413
414class MyThread : public OpenThreads::Thread {
415public:
416    void run(void) { }
417};
418
419class NotifyThread : public OpenThreads::Thread {
420public:
421
422    NotifyThread(osg::NotifySeverity level, const std::string& message):
423    _done(false),
424    _level(level),
425    _message(message) {}
426
427    ~NotifyThread()
428    {
429        _done = true;
430        while(isRunning())
431        {
432            OpenThreads::Thread::YieldCurrentThread();
433        }
434    }
435
436    void run(void)
437    {
438        std::cout << "Entering thread ..." <<_message<< std::endl;
439
440        unsigned int count=0;
441
442        while(!_done)
443        {
444            ++count;
445#if 1
446            osg::notify(_level)<<_message<<this<<"\n";
447#else
448            osg::notify(_level)<<_message<<this<<std::endl;
449#endif
450        }
451
452        std::cout << "Leaving thread ..." <<_message<< " count="<<count<<std::endl;
453    }
454
455    bool                  _done;
456    osg::NotifySeverity   _level;
457    std::string           _message;
458 
459};
460
461void testThreadInitAndExit()
462{
463    std::cout<<"******   Running thread start and delete test   ****** "<<std::endl;
464
465    {
466        MyThread thread;
467        thread.startThread();
468    }
469   
470    // add a sleep to allow the thread start to fall over it its going to.
471    OpenThreads::Thread::microSleep(500000);
472   
473    std::cout<<"pass    thread start and delete test"<<std::endl<<std::endl;
474
475
476    std::cout<<"******   Running notify thread test   ****** "<<std::endl;
477
478    {
479        NotifyThread thread1(osg::INFO,"thread one:");
480        NotifyThread thread2(osg::INFO,"thread two:");
481        NotifyThread thread3(osg::INFO,"thread three:");
482        NotifyThread thread4(osg::INFO,"thread four:");
483        thread1.startThread();
484        thread2.startThread();
485        thread3.startThread();
486        thread4.startThread();
487
488        // add a sleep to allow the thread start to fall over it its going to.
489        OpenThreads::Thread::microSleep(5000000);
490    }
491
492    std::cout<<"pass    noitfy thread test."<<std::endl<<std::endl;
493}
494
495void testPolytope()
496{
497    osg::Polytope pt;
498    pt.setToBoundingBox(osg::BoundingBox(-1000, -1000, -1000, 1000, 1000, 1000));
499    bool bContains = pt.contains(osg::Vec3(0, 0, 0));
500    if (bContains)
501    {
502        std::cout<<"Polytope pt.contains(osg::Vec3(0, 0, 0)) has succeeded."<<std::endl;
503    }
504    else
505    {
506        std::cout<<"Polytope pt.contains(osg::Vec3(0, 0, 0)) has failed."<<std::endl;
507    }
508
509}
510
511
512int main( int argc, char** argv )
513{
514    osg::ArgumentParser arguments(&argc,argv);
515
516    // set up the usage document, in case we need to print out how to use this program.
517    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which runs units tests.");
518    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options]");
519    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
520    arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests.");
521    arguments.getApplicationUsage()->addCommandLineOption("quat","Display extended quaternion tests.");
522    arguments.getApplicationUsage()->addCommandLineOption("quat_scaled sx sy sz","Display extended quaternion tests of pre scaled matrix.");
523    arguments.getApplicationUsage()->addCommandLineOption("sizeof","Display sizeof tests.");
524    arguments.getApplicationUsage()->addCommandLineOption("matrix","Display qualified tests.");
525    arguments.getApplicationUsage()->addCommandLineOption("performance","Display qualified tests.");
526 
527
528    if (arguments.argc()<=1)
529    {
530        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
531        return 1;
532    }
533
534    bool printQualifiedTest = false;
535    while (arguments.read("qt")) printQualifiedTest = true;
536
537    bool printMatrixTest = false;
538    while (arguments.read("matrix")) printMatrixTest = true;
539
540    bool printSizeOfTest = false;
541    while (arguments.read("sizeof")) printSizeOfTest = true;
542
543    bool printQuatTest = false;
544    while (arguments.read("quat")) printQuatTest = true;
545
546    int numReadThreads = 0;
547    while (arguments.read("read-threads", numReadThreads)) {}
548
549    bool printPolytopeTest = false;
550    while (arguments.read("polytope")) printPolytopeTest = true;
551   
552    bool doTestThreadInitAndExit = false;
553    while (arguments.read("thread")) doTestThreadInitAndExit = true;
554
555    osg::Vec3d quat_scale(1.0,1.0,1.0);
556    while (arguments.read("quat_scaled", quat_scale.x(), quat_scale.y(), quat_scale.z() )) printQuatTest = true;
557
558    bool performanceTest = false;
559    while (arguments.read("p") || arguments.read("performance")) performanceTest = true;
560
561    // if user request help write it out to cout.
562    if (arguments.read("-h") || arguments.read("--help"))
563    {
564        std::cout<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl;
565        arguments.getApplicationUsage()->write(std::cout,arguments.getApplicationUsage()->getCommandLineOptions());
566        return 1;
567    }
568
569    // any option left unread are converted into errors to write out later.
570    arguments.reportRemainingOptionsAsUnrecognized();
571
572    // report any errors if they have occurred when parsing the program arguments.
573    if (arguments.errors())
574    {
575        arguments.writeErrorMessages(std::cout);
576        return 1;
577    }
578   
579    if (printQuatTest)
580    {
581        testQuat(quat_scale);
582    }
583
584    if (printMatrixTest)
585    {
586        std::cout<<"******   Running matrix tests   ******"<<std::endl;
587
588        testFrustum(-1,1,-1,1,1,1000);
589        testFrustum(0,1,1,2,2.5,100000);
590
591        testOrtho(0,1,1,2,2.1,1000);
592        testOrtho(-1,10,1,20,2.5,100000);
593
594        testPerspective(20,1,1,1000);
595        testPerspective(90,2,1,1000);
596
597        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
598        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(1.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
599       
600        testMatrixInvert(osg::Matrix(0.999848,  -0.002700,  0.017242, -0.1715,
601                                     0,         0.987960,   0.154710,  0.207295,
602                                     -0.017452, -0.154687,  0.987809, -0.98239,
603                                     0,         0,          0,         1));
604
605        testMatrixInvert(osg::Matrix(0.999848,  -0.002700,  0.017242,   0.0,
606                                     0.0,        0.987960,   0.154710,   0.0,
607                                     -0.017452, -0.154687,  0.987809,   0.0,
608                                     -0.1715,    0.207295,  -0.98239,   1.0));
609
610    }
611   
612    if (printSizeOfTest)
613    {
614        std::cout<<"**** sizeof() tests  ******"<<std::endl;
615       
616        sizeOfTest();
617
618        std::cout<<std::endl;
619    }
620
621
622    if (performanceTest)
623    {
624        std::cout<<"**** performance tests  ******"<<std::endl;
625       
626        runPerformanceTests();
627    }
628
629    if (numReadThreads>0)
630    {
631        runMultiThreadReadTests(numReadThreads);
632        return 0;
633    }
634
635
636    if (printPolytopeTest)
637    {
638        testPolytope();
639    }
640
641
642    if (printQualifiedTest)
643    {
644         std::cout<<"*****   Qualified Tests  ******"<<std::endl;
645
646         osgUtx::QualifiedTestPrinter printer;
647         osgUtx::TestGraph::instance().root()->accept( printer );   
648         std::cout<<std::endl;
649    }
650
651    if (doTestThreadInitAndExit)
652    {
653        testThreadInitAndExit();
654    }
655
656    std::cout<<"******   Running tests   ******"<<std::endl;
657
658    // Global Data or Context
659    osgUtx::TestContext ctx;
660    osgUtx::TestRunner runner( ctx );
661    runner.specify("root");
662
663    osgUtx::TestGraph::instance().root()->accept( runner );
664
665    return 0;
666}
Note: See TracBrowser for help on using the browser.