File: main.cpp

package info (click to toggle)
openni 1.5.4.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 45,208 kB
  • sloc: cpp: 116,706; ansic: 58,794; sh: 10,287; cs: 7,698; java: 7,402; python: 1,544; makefile: 492; xml: 167
file content (124 lines) | stat: -rw-r--r-- 6,160 bytes parent folder | download | duplicates (7)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/****************************************************************************
*                                                                           *
*  OpenNI 1.x Alpha                                                         *
*  Copyright (C) 2011 PrimeSense Ltd.                                       *
*                                                                           *
*  This file is part of OpenNI.                                             *
*                                                                           *
*  OpenNI is free software: you can redistribute it and/or modify           *
*  it under the terms of the GNU Lesser General Public License as published *
*  by the Free Software Foundation, either version 3 of the License, or     *
*  (at your option) any later version.                                      *
*                                                                           *
*  OpenNI is distributed in the hope that it will be useful,                *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
*  GNU Lesser General Public License for more details.                      *
*                                                                           *
*  You should have received a copy of the GNU Lesser General Public License *
*  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.           *
*                                                                           *
****************************************************************************/
#include "SampleManager.h"

/// @defgroup UserSelectionMain User selection main
/// @brief User selection main.cpp functions
/// @ingroup UserSelectionSampleFiles

/// @brief Method which prints the usage and exits the program.
///
/// @param filename The filename of the executable
/// @ingroup UserSelectionMain
void UsageAndExit(char* filename)
{
    printf("\nUsage: %s [-recordingFilename Filename] [-s selectorType] [-ShowLowConfidence]\n\n\n" , filename);
    printf("-RecordingFilename Filename         Use the recording in Filename for input.\n\n");
    printf("-ShowLowConfidence                  Draws limbs with low confidence as dotted/dashed lines (hidden by default)\n\n");
    printf("-s selectorType                     Chooses the selector type to use (i.e. how to select which users to track).\n");
    printf("                -ClosestSelector N: The N closest users are tracked.\n");
    printf("                -SingleWave:        Whichever user waved last is tracked.\n");
    printf("                -MultipleWave N:    Upto N skeleton are tracked. Wave used to select/unselect user for tracking.\n\n");
    printf("   Note:\n");
    printf("        - If the '-s' option is omitted,  ClosestSelector with a value of 1 is used by default.\n");
    printf("        - The '-s' option will be ignored if calibration pose is required. In this case, anyone striking that pose will be tracked.\n\n");

    exit(EXIT_FAILURE);
}



/// @brief The main function of the sample
/// 
/// This is the main function of the sample. Its purpose is to be the starting point for the
/// sample and according to the command line arguments, to decide which sample behavior to use.
/// @ingroup UserSelectionMain
int main(int argc, char** argv)
{    
    SampleManager* pSampleManager=NULL; // will hold the sample manager which initializes and runs the sample
    if(argc>1)
    {
        // check if the argument is asking for help...
        if(xnOSStrCmp(argv[1],"--help")==0 ||
           xnOSStrCmp(argv[1],"-help")==0 ||
           xnOSStrCmp(argv[1],"/help")==0 ||
           xnOSStrCmp(argv[1],"\\help")==0 ||
           xnOSStrCmp(argv[1],"?")==0 ||
           xnOSStrCmp(argv[1],"--?")==0 ||
           xnOSStrCmp(argv[1],"-?")==0 ||
           xnOSStrCmp(argv[1],"/?")==0 ||
           xnOSStrCmp(argv[1],"\\?")==0)
        {
            UsageAndExit(argv[0]);
        }

        // go over the arguments and see if we have the '-s' switch. If so it means we
        // are going to choose the selector type.
        for(int i=1; i<argc-1; i++)
        {
            if(xnOSStrCmp(argv[i],"-s")==0)
            {
                if(xnOSStrCmp(argv[i+1],"ClosestSelector")==0)
                {
                    // we are in the option '-s ClosestSelector N'. 
                    if(argc<=i+2 || strlen(argv[i+2])>2)
                    {
                        UsageAndExit(argv[0]); // either there is no N at all or it is more than 1 digit
                    }
                    XnUInt32 n=argv[i+2][0]-'0'; // translate digit to number
                    pSampleManager=XN_NEW(ClosestSampleManager,n); // choose ClosestSelector with n
                }
                else if(xnOSStrCmp(argv[i+1],"SingleWave")==0)
                {
                    // option is '-s SingleWave'
                    pSampleManager=XN_NEW(SingleWaveSampleManager);
                }
                else if(xnOSStrCmp(argv[i+1],"MultipleWave")==0)
                {
                    // option is '-s SingleWave N'
                    if(argc<=i+2 || strlen(argv[i+2])>2)
                    {
                        UsageAndExit(argv[0]); // either there is no N at all or it is more than 1 digit
                    }
                    XnUInt32 n=argv[i+2][0]-'0'; // translate digit to number
                    pSampleManager=XN_NEW(MultipleWaveSampleManager,n);
                }
                else
                {
                    // an illegal option was used...
                    UsageAndExit(argv[0]);
                }
                break; // we found the switch so we ignore all others
            }
        }
    }
    if(pSampleManager==NULL) // by default we use the closest detector option
    {
        pSampleManager=XN_NEW(ClosestSampleManager,1); // choose the default.
    }

    if(pSampleManager->StartSample(argc,argv)!=XN_STATUS_OK) 
    {
		XN_DELETE(pSampleManager);
        UsageAndExit(argv[0]); // The manager will only return if it fails to initialize...
    }
}