File: TestOBJImporter.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (99 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (3)
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

#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 "vtkTestUtilities.h"
#include "vtksys/SystemTools.hxx"

namespace
{
int s_interactive = 0;

bool bInteractive()
{
    return (s_interactive>0);
}

}

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::vector<std::string> tmp1,tmp2;
    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)
    {
      s_interactive = 1;
      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;
    }
    if( bInteractive() )
    {
        renWin->SetSize(800,600);
        renWin->SetAAFrames(3);
        iren->Start();
    }
    return 0;
}