int main( ){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  // Create the OSG world
  osg::ref_ptr< osaOSGWorld > world = new osaOSGWorld;

  // Create OSG camera
  int x = 0, y = 0;
  int width = 640, height = 480;
  double Znear = 0.1, Zfar = 10.0;

  osg::Node::NodeMask maskleft  = 0x01;
  osg::Node::NodeMask maskright = 0x02;

  mtsOSGStereo* camera;
  camera = new mtsOSGStereo( "camera",
			     world,
			     x, y,
			     width, height,
			     55.0, ((double)width)/((double)height),
			     Znear, Zfar,
			     0.1 );
  camera->setCullMask( maskleft, osaOSGStereo::LEFT );
  camera->setCullMask( maskright, osaOSGStereo::RIGHT );
  taskManager->AddComponent( camera );

  // create the hubble motion
  HubbleMotion hmotion;
  taskManager->AddComponent( &hmotion );


  // create hubble
  cmnPath path;
  path.AddRelativeToCisstShare("/models/hubble");
  path.AddRelativeToCisstShare("/movies");

  vctFrame4x4<double> Rt( vctMatrixRotation3<double>(),
			  vctFixedSizeVector<double,3>( 0.0, 0.0, 0.5 ) );
  mtsOSGBody* hubble;
  hubble = new mtsOSGBody( "hubble", path.Find("hst.3ds"), world, Rt, 1.0, .5 );
  taskManager->AddComponent( hubble );


  // connect the motion to hubble
  taskManager->Connect( hubble->GetName(), "Input",
  			hmotion.GetName(), "Output" );


  // start the components
  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );
  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );


  // Start the svl stuff
  svlInitialize();

  // Creating SVL objects
  svlStreamManager streamleft;
  svlFilterSourceVideoFile sourceleft(1);
  svlOSGImage imageleft( -0.5, -0.5, 1, 1, world );

  // Configure the filters
  sourceleft.SetFilePath( path.Find( "left.mpg" ) );
  imageleft.setNodeMask( maskleft );

  streamleft.SetSourceFilter( &sourceleft );
  sourceleft.GetOutput()->Connect( imageleft.GetInput() );

  svlStreamManager streamright;
  svlFilterSourceVideoFile sourceright(1);
  svlOSGImage imageright( -0.5, -0.5, 1, 1, world );

  sourceright.SetFilePath( path.Find( "right.mpg" ) );
  imageright.setNodeMask( maskright );

  streamright.SetSourceFilter( &sourceright );
  sourceright.GetOutput()->Connect( imageright.GetInput() );

  // start the streams
  if (streamleft.Play() != SVL_OK)
    { std::cerr << "Cannot start left stream." <<std::endl; }

  if (streamright.Play() != SVL_OK)
    { std::cerr << "Cannot start right stream." <<std::endl; }

  std::cout << "ENTER to exit." << std::endl;
  cmnGetChar();
  cmnGetChar();

  streamleft.Release();
  streamright.Release();

  taskManager->KillAll();
  taskManager->Cleanup();

  return 0;

}
Esempio n. 2
0
int main(int argc, char *argv[])
{
   // log configuration
    cmnLogger::SetMask(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskDefaultLog(CMN_LOG_ALLOW_ALL);
//    cmnLogger::AddChannel(std::cout, CMN_LOG_ALLOW_ERRORS_AND_WARNINGS);
    cmnLogger::AddChannel(std::cout, CMN_LOG_ALLOW_ALL);


    // create our components
    mtsComponentManager * componentManager;
    componentManager = mtsManagerLocal::GetInstance();

    QApplication application(argc, argv);
    svlInitialize();
    sdpPlayerManager * playerManager = new sdpPlayerManager("PlayerManager", 50.0 * cmn_ms);
   // sdpPlayerExample * player = new sdpPlayerExample("Player", 1.0 * cmn_ms);
    sdpPlayerVideo * videoPlayer = new sdpPlayerVideo("VideoPlayer", 15.0 * cmn_ms);
    sdpPlayerPlot2D * plotPlayer = new sdpPlayerPlot2D("PlotPlayer", 40.0 * cmn_ms);
    sdpPlayerNotes *notePlayer  = new sdpPlayerNotes("NotePlayer", 40*cmn_ms);


#ifdef sawPlayer_has_sawOpenAL
    sdpPlayerAudio * audioPlayer = new sdpPlayerAudio("AudioPlayer", 40.0 * cmn_ms);
    componentManager->AddComponent(audioPlayer);
#endif

    componentManager->AddComponent(playerManager);
    componentManager->AddComponent(notePlayer);

  //  componentManager->AddComponent(player);
    componentManager->AddComponent(videoPlayer);
    componentManager->AddComponent(plotPlayer);

    //Connect provider/required interface of Base Class for Qt Thread
 //   componentManager->Connect(player->GetName(), "GetStatus", player->GetName(), "ProvidesStatus");
    componentManager->Connect(videoPlayer->GetName(), "GetStatus", videoPlayer->GetName(), "ProvidesStatus");
    componentManager->Connect(plotPlayer->GetName(), "GetStatus",plotPlayer->GetName(), "ProvidesStatus");
    componentManager->Connect(notePlayer->GetName(), "GetStatus",notePlayer->GetName(), "ProvidesStatus");

    //Connect componets-added interfaces for Qt Thread
    componentManager->Connect(plotPlayer->GetName(), "Get2DPlotStatus",plotPlayer->GetName(), "Provides2DPlot");

 #ifdef sawPlayer_has_sawOpenAL
    componentManager->Connect(audioPlayer->GetName(), "GetStatus", audioPlayer->GetName(), "ProvidesStatus");
 #endif

    // create the components, i.e. find the commands
    componentManager->CreateAll();
    componentManager->WaitForStateAll(mtsComponentState::READY);

    // start the periodic Run
    componentManager->StartAll();
    componentManager->WaitForStateAll(mtsComponentState::ACTIVE);

 //   playerManager->AddPlayer(player);
    playerManager->AddPlayer(videoPlayer);
    playerManager->AddPlayer(plotPlayer);
    playerManager->AddPlayer(notePlayer);


#ifdef sawPlayer_has_sawOpenAL
    playerManager->AddPlayer(audioPlayer);
#endif


    playerManager->Configure();
 //   player->Configure();
    videoPlayer->Configure();
    plotPlayer->Configure();
    notePlayer->Configure();

#ifdef sawPlayer_has_sawOpenAL
    audioPlayer->Configure();
#endif


    application.setStyle("Plastique");
    application.exec();

    componentManager->KillAll();
    componentManager->WaitForStateAll(mtsComponentState::FINISHED, 2.0 * cmn_s);

    componentManager->Cleanup();

    return 0;
}
Esempio n. 3
0
int main(int argc, char** argv)
{
    cmnLogger::SetMask(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskFunction(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskDefaultLog(CMN_LOG_ALLOW_ALL);

    cmnCommandLineOptions options;
    const std::string configFilePrefix = "camera-viewer";

    int portNumber = 0;
    std::string codecName = ".njpg";

    int numberOfChannels = 1;
    int latencyInFrames = 0;
    unsigned int width = 0;
    unsigned int height = 0;

    int numberOfThreads = 4;
    options.AddOptionOneValue("t", "threads",
                              "Number of threads, default is 4",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &numberOfThreads);

    options.AddOptionOneValue("c", "channels",
                              "Number of channels, 1 for mono (default), 2 for stereo",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &numberOfChannels);

    options.AddOptionOneValue("p", "port",
                              "IP port for network based codec",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &portNumber);

    options.AddOptionNoValue("d", "dual-port",
                             "Create two ports to send left/right separately (default is single port)",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionOneValue("w", "width",
                              "Resize width (if specified, requires height)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &width);

    options.AddOptionOneValue("h", "height",
                              "Resize height (if specified, requires width)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &height);

    options.AddOptionNoValue("f", "flip-horizontal",
                             "Flip image left to right",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionOneValue("l", "latency",
                              "Add latency (in number of frames)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &latencyInFrames);

    options.AddOptionNoValue("s", "save-configuration",
                             std::string("Save camera configuration in ") + configFilePrefix + std::string("-{mono,stereo}.dat"),
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionNoValue("n", "no-window",
                             "don't display preview",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    std::string errorMessage;
    if (!options.Parse(argc, argv, errorMessage)) {
        std::cerr << "Error: " << errorMessage << std::endl;
        options.PrintUsage(std::cerr);
        return -1;
    }

    if ((numberOfChannels != 1) && (numberOfChannels != 2)) {
        std::cerr << "Error: number of channels can be either 1 or 2." << std::endl;
        return -1;
    }

    std::string configFile = configFilePrefix;
    if (numberOfChannels == 1) {
        configFile.append("-mono.dat");
    } else {
        configFile.append("-stereo.dat");
    }

    if ((width != 0) || (height != 0)) {
        if ((width == 0) || (height == 0)) {
            std::cerr << "Error: you need to specify both width and height, both need to be greater than 0." << std::endl;
            return -1;
        }
    }

    svlInitialize();

    // connect the source to the stream
    svlFilterSourceVideoCapture source(numberOfChannels);
    if (source.LoadSettings(configFile.c_str()) != SVL_OK) {
        source.DialogSetup(SVL_LEFT);
        source.DialogSetup(SVL_RIGHT);
    }
    if (options.IsSet("save-configuration")) {
        source.SaveSettings(configFile.c_str());
    }

    svlFilterImageWindow previewWindow;
    previewWindow.SetName("Video");
    previewWindow.SetTitle("cisstCameraViewer");

    svlStreamManager stream(numberOfThreads);
    stream.SetSourceFilter(&source);

    // connect the source to next filter
    svlFilterOutput * output;
    output = source.GetOutput();

    // first resize if needed
    svlFilterImageResizer resize;
    if (width != 0) {
        resize.SetName("Resize");
        resize.SetInterpolation(true);
        resize.SetOutputSize(width, height, SVL_LEFT);
        resize.SetOutputSize(width, height, SVL_RIGHT);
        output->Connect(resize.GetInput());
        output = resize.GetOutput();
    }

    // flip if needed
    svlFilterImageFlipRotate flip;
    if (options.IsSet("flip-horizontal")) {
        flip.SetHorizontalFlip(true);
        output->Connect(flip.GetInput());
        output = flip.GetOutput();
    }

    // latency if needed
    svlFilterAddLatency latency;
    if (latencyInFrames > 0) {
        latency.SetFrameDelayed(latencyInFrames);
        output->Connect(latency.GetInput());
        output = latency.GetOutput();
    }

    // writer on network
    svlFilterVideoFileWriter writer;
    svlFilterStereoImageJoiner stereoJoiner;

    if (options.IsSet("port")) {
        // detect if codec is available
        svlVideoCodecBase * codec = svlVideoIO::GetCodec(codecName);
        if (codec == 0) {
            std::string formatlist;
            svlVideoIO::GetFormatList(formatlist);
            std::cerr << "Error: can't find codec " << codecName << std::endl
                      << "Supported formats:" << std::endl
                      << formatlist << std::endl;
            return -1;
        }
        svlVideoIO::Compression * compr = codec->GetCompression();
        svlVideoIO::ReleaseCodec(codec);
        compr->data[0] = 75;

        writer.SetCodecParams(compr);
        svlVideoIO::ReleaseCompression(compr);

        std::stringstream filePath;
        filePath << "@" << portNumber << codecName;
        std::cout << "Opening network using " << filePath.str() << std::endl;

        // stereo
        if (numberOfChannels == 2) {
            // two channels
            if (options.IsSet("dual-port")) {
                writer.SetFilePath(filePath.str(), SVL_LEFT);
                filePath.str(std::string());
                filePath << "@" << portNumber + 1 << codecName;
                std::cout << "Opening network using " << filePath.str() << std::endl;
                writer.SetFilePath(filePath.str(), SVL_RIGHT);
            } else {
                // join the two channels using the stereo image joiner
                output->Connect(stereoJoiner.GetInput());
                output = stereoJoiner.GetOutput();
                writer.SetFilePath(filePath.str());
            }
        } else {
            writer.SetFilePath(filePath.str());
        }
        writer.OpenFile();

        output->Connect(writer.GetInput());
        output = writer.GetOutput();
    }

    // connect the last filter to preview if desired
    if (!options.IsSet("no-window")) {
        output->Connect(previewWindow.GetInput());
    }

    if (stream.Play() != SVL_OK) {
        std::cerr << "Failed to start the stream." << std::endl;
        return 0;
    }
    std::cout << argv[0] << " started, press 'q' to stop." << std::endl;

    char c;
    do {
        c = cmnGetChar();
        switch (c) {
        case '+':
            latency.UpLatency();
            break;
        case '-':
            latency.DownLatency();
            break;
        }
    } while (c != 'q');

    std::cout << "Stopping video stream." << std::endl;
    stream.Release();

    cmnLogger::Kill();
    return 0;
}