bool MultiLayerMovie::setupAnimations()
{
   // Create the controller
   Service<AnimationServices> pServices;

   AnimationController* pController = pServices->getAnimationController("MultiLayerMovie");
   if (pController != NULL)
   {
      pServices->destroyAnimationController(pController);
   }

   pController = pServices->createAnimationController("MultiLayerMovie", FRAME_TIME);
   if (pController == NULL)
   {
      return false;
   }
   pController->setCanDropFrames(false);

   // Set the controller into each of the views
   SpatialDataView* pView = dynamic_cast<SpatialDataView*>(mpWindow->getView());
   if (pView == NULL)
   {
      pServices->destroyAnimationController(pController);
      return false;
   }

   pView->setAnimationController(pController);

   // Create the animations for each layer
   Animation* pAnimation1 = pController->createAnimation("MultiLayerMovie1");
   Animation* pAnimation2 = pController->createAnimation("MultiLayerMovie2");
   Animation* pAnimation3 = pController->createAnimation("MultiLayerMovie3");
   if (pAnimation1 == NULL || pAnimation2 == NULL || pAnimation3 == NULL)
   {
      pServices->destroyAnimationController(pController);
      return false;
   }

   // Set up the frames for each animation
   const int timeOffset = mNumBands/4;
   vector<AnimationFrame> frames1;
   vector<AnimationFrame> frames2;
   vector<AnimationFrame> frames3;
   for (int i = 0; i < mNumBands; ++i)
   {
      AnimationFrame frame1("frame", i, static_cast<double>(i)/mNumBands);
      AnimationFrame frame2("frame", i, static_cast<double>(i+timeOffset)/(mNumBands+timeOffset));
      AnimationFrame frame3("frame", i, static_cast<double>(i+2*timeOffset)/(mNumBands+timeOffset));
      frames1.push_back(frame1);
      frames2.push_back(frame2);
      frames3.push_back(frame3);
   }

   // Set the frames into the animations
   pAnimation1->setFrames(frames1);
   pAnimation2->setFrames(frames2);
   pAnimation3->setFrames(frames3);

   // Assign the animations to the layers
   mpLayer1->setAnimation(pAnimation1);
   mpLayer2->setAnimation(pAnimation2);
   mpLayer3->setAnimation(pAnimation3);

   return true;
}
示例#2
0
bool VideoImporter::execute(PlugInArgList *pInArgList, PlugInArgList *pOutArgList)
{
   if(pInArgList == NULL)
   {
      return false;
   }
   // Create a message log step
   mProgress = ProgressTracker(pInArgList->getPlugInArgValue<Progress>(ProgressArg()),
      "Execute video importer", "coan", "{6385aa93-ff7f-4ee7-9308-b3476aca544b}");

   DataElement* pElmnt = pInArgList->getPlugInArgValue<DataElement>(ImportElementArg());
   mpRasterElement = dynamic_cast<RasterElement*>(pElmnt);
   mpStreamElement = dynamic_cast<Any*>(pElmnt);
   if (mpRasterElement == NULL && mpStreamElement == NULL)
   {
      mProgress.report("The data element input value is invalid.", 0, ERRORS, true);
      return false;
   }

   if (mpRasterElement != NULL)
   {
      mProgress.report("Initialize display.", 1, NORMAL);
      if (!mpRasterElement->createDefaultPager())
      {
         //return checkAbortOrError("Could not allocate resources for new RasterElement", pStep.get());
         return false;
      }
      // schedule load of first frame
      Any* pParent = dynamic_cast<Any*>(mpRasterElement->getParent());
      VERIFY(pParent != NULL);
      VideoStream* pStream = dynamic_cast<VideoStream*>(pParent->getData());
      VERIFY(pStream != NULL);
      if (!pStream->setDisplay(mpRasterElement))
      {
         mProgress.report("Unable to display the stream.", 0, ERRORS, true);
         return false;
      }

      // Create the view
      if(!isBatch() && !Service<SessionManager>()->isSessionLoading())
      {
         SpatialDataView *pView = createView();
         if(pView == NULL)
         {
            mProgress.report("The view could not be created.", 0, ERRORS, true);
            return false;
         }

         // Add the view to the output arg list
         if(pOutArgList != NULL)
         {
            pOutArgList->setPlugInArgValue("View", pView);
         }
      }
      mProgress.report("Display initialization complete.", 100, NORMAL);
   }
   else if (mpStreamElement != NULL)
   {
      mProgress.report("Initialize video stream.", 1, NORMAL);
      // initialize the stream data
      VideoStream* pStream = NULL;
      std::vector<PlugIn*> instances = Service<PlugInManagerServices>()->getPlugInInstances("Video Stream Manager");
      StreamManager* pStreamManager = instances.empty() ? NULL : dynamic_cast<StreamManager*>(instances.front());
      if (pStreamManager != NULL)
      {
         if (pStreamManager->initializeStream(mpStreamElement))
         {
            pStream = dynamic_cast<VideoStream*>(mpStreamElement->getData());
         }
      }
      if (pStream == NULL)
      {
         mProgress.report("Unable to initialize the video stream.", 0, ERRORS, true);
         return false;
      }
      
      // create animation
      AnimationController* pController = Service<AnimationServices>()->getAnimationController(mpStreamElement->getName());
      if (pController == NULL)
      {
         pController = Service<AnimationServices>()->createAnimationController(mpStreamElement->getName(), FRAME_TIME);
      }
      if (pController == NULL)
      {
         mProgress.report("Unable to create animation.", 0, ERRORS, true);
         return false;
      }
      if (!isBatch())
      {
         AnimationToolBar* pToolBar = static_cast<AnimationToolBar*>(Service<DesktopServices>()->getWindow("Animation", TOOLBAR));
         VERIFY(pToolBar);
         pToolBar->setAnimationController(pController);
      }
      Animation* pAnim = pController->createAnimation(mpStreamElement->getName());
      VERIFY(pAnim != NULL);
      if (!pStream->setAnimation(pAnim, pController))
      {
         mProgress.report("Unable to create animation.", 0, ERRORS, true);
         return false;
      }

      mProgress.report("Video stream initialization complete.", 100, NORMAL);
   }

   mProgress.upALevel();
   return true;
}