File: TestOBJImporter.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (103 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

#include "vtkVRMLImporter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkOBJImporter.h"
#include "vtkTestUtilities.h"
#include "vtkNew.h"
#include "vtkJPEGWriter.h"
#include "vtkPNGWriter.h"
#include "vtkImageCanvasSource2D.h"
#include "vtkImageCast.h"
#include "vtkCamera.h"

#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtksys/SystemTools.hxx"

int TestOBJImporter( int argc, char * argv [] )
{
    // Files for testing demonstrate updated functionality for OBJ import:
    //       polydata + textures + actor properties all get loaded.

    if(argc < (5))
    {
      std::cerr<<"expected TestName -D  File1.obj [File2.obj.mtl]  [texture1]  [texture2]  ... "<<std::endl;
      return -1;
    }

    std::string filenameOBJ(argv[2]);

    std::string filenameMTL,texfile1,texfile2;

    if(argc >= 6)
    {
      filenameMTL = argv[3];
    }

    if(argc >= 7)
    {
      texfile1 = argv[4];
    }

    if(argc >= 8)
    {
      texfile2 = argv[5];
    }

    std::string texture_path1 = vtksys::SystemTools::GetFilenamePath(texfile1);
    std::string texture_path2 = vtksys::SystemTools::GetFilenamePath(texfile2);
    if( 0 != texture_path1.compare(texture_path2) )
    {
      std::cerr<<" texture files should be in the same path: "<<texture_path1<<std::endl;
      return -2;
    }

    int lastArg = (argc <= 8) ? (argc-1) : 7;
    std::string tmppath(argv[lastArg]);
    vtkNew<vtkOBJImporter> importer;


    if(argc > 8)
    {
      importer->DebugOn();
    }

    importer->SetFileName(filenameOBJ.data());
    importer->SetFileNameMTL(filenameMTL.data());
    importer->SetTexturePath(texture_path1.data());

    vtkNew<vtkRenderer> ren;
    vtkNew<vtkRenderWindow> renWin;
    vtkNew<vtkRenderWindowInteractor> iren;

    renWin->AddRenderer(ren.Get());
    iren->SetRenderWindow(renWin.Get());
    importer->SetRenderWindow(renWin.Get());
    importer->Update();

    ren->ResetCamera();

    if( 1 > ren->GetActors()->GetNumberOfItems() )
    {
      std::cerr << "failed to get an actor created?!" << std::endl;
      return -1;
    }
    ren->GetActiveCamera()->SetPosition(10,10,-10);
    ren->ResetCamera();
    int retVal = vtkRegressionTestImage(renWin.GetPointer());
    if( retVal == vtkRegressionTester::DO_INTERACTOR )
    {
      renWin->SetSize(800,600);
      renWin->SetAAFrames(3);
      iren->Start();
    }

    // Some tests do not produce images... allow them to pass.
    // But if we had an image, it must be within the threshold:
    return (
      retVal == vtkRegressionTester::PASSED ||
      retVal == vtkRegressionTester::NOT_RUN) ?
      0 : 1;
}