//--------------------------------------------------------------
        /// Lerp Between Frames
        //--------------------------------------------------------------
        SkinnedAnimation::FrameCUPtr SkinnedAnimationGroup::LerpBetweenFrames(const SkinnedAnimation::Frame* inFrameA, const SkinnedAnimation::Frame* inFrameB, f32 infInterpFactor)
        {
            SkinnedAnimation::FrameUPtr outFrame(new SkinnedAnimation::Frame());
			
            if(inFrameA != nullptr && inFrameB != nullptr)
            {
                //iterate through each translation
                outFrame->m_nodeTranslations.reserve(inFrameB->m_nodeTranslations.size());
                std::vector<Core::Vector3>::const_iterator transAIt = inFrameA->m_nodeTranslations.begin();
                for (std::vector<Core::Vector3>::const_iterator transBIt = inFrameB->m_nodeTranslations.begin();
                     transAIt != inFrameA->m_nodeTranslations.end() && transBIt != inFrameB->m_nodeTranslations.end();)
                {
                    //lerp
                    Core::Vector3 newTrans = Core::MathUtils::Lerp(infInterpFactor, *transAIt, *transBIt);
                    
                    //add to frame
                    outFrame->m_nodeTranslations.push_back(newTrans);
                    
                    //incriment the iterators
                    ++transAIt;
                    ++transBIt;
                }
                
                //iterate through each orientation
                outFrame->m_nodeOrientations.reserve(inFrameB->m_nodeOrientations.size());
                std::vector<Core::Quaternion>::const_iterator orientAIt = inFrameA->m_nodeOrientations.begin();
                for (std::vector<Core::Quaternion>::const_iterator orientBIt = inFrameB->m_nodeOrientations.begin();
                     orientAIt != inFrameA->m_nodeOrientations.end() && orientBIt != inFrameB->m_nodeOrientations.end();)
                {
                    //lerp
                    Core::Quaternion newOrient = Core::Quaternion::Slerp(*orientAIt, *orientBIt, infInterpFactor);
                    
                    //add to frame
                    outFrame->m_nodeOrientations.push_back(newOrient);
                    
                    //incriment the iterators
                    ++orientAIt;
                    ++orientBIt;
                }
                
                //iterate through each scale
                outFrame->m_nodeScales.reserve(inFrameB->m_nodeScales.size());
                std::vector<Core::Vector3>::const_iterator scaleAIt = inFrameA->m_nodeScales.begin();
                for (std::vector<Core::Vector3>::const_iterator scaleBIt = inFrameB->m_nodeScales.begin();
                     scaleAIt != inFrameA->m_nodeScales.end() && scaleBIt != inFrameB->m_nodeScales.end();)
                {
                    //lerp
                    Core::Vector3 newScale = Core::MathUtils::Lerp(infInterpFactor, *scaleAIt, *scaleBIt);
                    
                    //add to frame
                    outFrame->m_nodeScales.push_back(newScale);
                    
                    //incriment the iterators
                    ++scaleAIt;
                    ++scaleBIt;
                }
            }
			
			return SkinnedAnimation::FrameCUPtr(std::move(outFrame));
        }
Esempio n. 2
0
void CCameraOpencv::slotTimeOut()
{
#ifdef DEBUG_VIDEO_TIME
    LOG_MODEL_DEBUG("CCameraOpencv", "CCameraOpencv::slotTimeOut threadid:0x%X", QThread::currentThread());
#endif

    cv::Mat frame;
#ifdef ANDROID
    if(!m_videoCapture.grab())
        return;
     m_videoCapture.retrieve(frame, CV_CAP_ANDROID_COLOR_FRAME_RGB);//cv::CAP_ANDROID_COLOR_FRAME_RGB
#else
    m_videoCapture >> frame;
    //因为opencv会在内部把图像转化为BGR格式  
    cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);  
#endif
    if(frame.empty())
        return;
    /*LOG_MODEL_DEBUG("CCameraOpencv", "frame.type:%d;format:%d", frame.type(), 
                #ifdef ANDROID
                    m_videoCapture.get(cv::CAP_PROP_ANDROID_PREVIEW_FORMAT)
                #else
                    m_videoCapture.get(cv::CAP_PROP_FORMAT)
                #endif
                    );
    */

    /*第一种转换方法:用QImage  
    QImage image((uchar*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888);  //RGB888就是RGB24即RGB  
    QVideoFrame outFrame(image);//*/

    //*第二种转换方法:用CDataVideoBuffer  
    QByteArray outData((const char*)frame.data, (int)(frame.total() * frame.channels()));
    //frame.total指图片像素个数,总字节数(dst.data)=dst.total*dst.channels()  
    //由QVideoFrame进行释放  
    CDataVideoBuffer* pBuffer = new CDataVideoBuffer(outData,
                            frame.cols,
                            frame.rows);
    //LOG_MODEL_DEBUG("CCameraOpencv", "CCameraOpencv format:%d", dbFormat);
    QVideoFrame outFrame(pBuffer,
                         QSize(frame.cols,
                               frame.rows),
                         QVideoFrame::Format_RGB24);//*/
#ifdef ANDROID
    emit sigCaptureRawFrame(outFrame);
#else
    emit sigCaptureFrame(outFrame);//opencv已经做过镜像了  
#endif
}
Esempio n. 3
0
void CVideoRenderer::RenderFrame(const cricket::VideoFrame *video_frame)
{
    if (!video_frame)
        return;

    const cricket::VideoFrame* frame =
        video_frame->GetCopyWithRotationApplied();

    SetSize(static_cast<int>(frame->GetWidth()),
            static_cast<int>(frame->GetHeight()));

    QImage outFrame(frame->GetWidth(), frame->GetHeight(), QImage::Format_ARGB32);
    //ARGB格式
    frame->ConvertToRgbBuffer(cricket::FOURCC_ARGB,
                              (uint8_t*)outFrame.bits(),
                              m_BitmapSize,
                              m_Width << 2);

    if(m_isLocale && m_pCallObject)
        emit m_pCallObject->sigRenderLocale(outFrame);
    else
        emit m_pCallObject->sigRenderRemote(outFrame);
}
Esempio n. 4
0
// Analysis_Hist::Analyze()
Analysis::RetType Analysis_Hist::Analyze() {
  // Set up dimensions
  // Size of histdata and dimensionArgs should be the same
  size_t total_bins = 0UL;
  for (unsigned int hd = 0; hd < N_dimensions_; hd++) {
    if ( setupDimension(dimensionArgs_[hd], *(histdata_[hd]), total_bins) ) 
      return Analysis::ERR;
  }
  // dimensionArgs no longer needed
  dimensionArgs_.clear();

  // Check that the number of data points in each dimension are equal
  std::vector<DataSet_1D*>::iterator ds = histdata_.begin();
  size_t Ndata = (*ds)->Size();
  ++ds;
  for (; ds != histdata_.end(); ++ds)
  {
    //mprintf("DEBUG: DS %s size %i\n",histdata[hd]->Name(),histdata[hd]->Xmax()+1);
    if (Ndata != (*ds)->Size()) {
      mprinterr("Error: Hist: Dataset %s has inconsistent # data points (%zu), expected %zu.\n",
                (*ds)->legend(), (*ds)->Size(), Ndata);
      return Analysis::ERR;
    }
  }
  mprintf("\tHist: %zu data points in each dimension.\n", Ndata);
  if (calcAMD_ && Ndata != amddata_->Size()) {
    mprinterr("Error: Hist: AMD data set size (%zu) does not match # expected data points (%zu).\n",
              amddata_->Size(), Ndata);
    return Analysis::ERR;
  }

  // Allocate bins
  mprintf("\tHist: Allocating histogram, total bins = %zu\n", total_bins);
  Bins_.resize( total_bins, 0.0 );

  // Bin data
  for (size_t n = 0; n < Ndata; n++) {
    long int index = 0;
    HdimType::const_iterator dim = dimensions_.begin();
    OffType::const_iterator bOff = binOffsets_.begin();
    for (std::vector<DataSet_1D*>::iterator ds = histdata_.begin();
                                            ds != histdata_.end(); ++ds, ++dim, ++bOff)
    {
      double dval = (*ds)->Dval( n );
      // Check if data is out of bounds for this dimension.
      if (dval > dim->Max() || dval < dim->Min()) {
        index = -1L;
        break;
      }
      // Calculate index for this particular dimension (idx)
      long int idx = (long int)((dval - dim->Min()) / dim->Step());
      if (debug_>1) mprintf(" [%s:%f (%li)],", dim->label(), dval, idx);
      // Calculate overall index in Bins, offset has already been calcd.
      index += (idx * (*bOff));
    }
    // If index was successfully calculated, populate bin
    if (index > -1L && index < (long int)Bins_.size()) {
      if (debug_ > 1) mprintf(" |index=%li",index);
      if (calcAMD_)
        Bins_[index] += exp( amddata_->Dval(n) );
      else
        Bins_[index]++;
    } else {
      mprintf("\tWarning: Frame %zu Coordinates out of bounds (%li)\n", n+1, index);
    }
    if (debug_>1) mprintf("}\n");
  }
  // Calc free energy if requested
  if (calcFreeE_) CalcFreeE();

  // Normalize if requested
  if (normalize_ != NO_NORM) Normalize();

  if (nativeOut_) {
    // Use Histogram built-in output
    PrintBins();
  } else {
    // Using DataFileList framework, set-up labels etc.
    if (N_dimensions_ == 1) {
      DataSet_double& dds = static_cast<DataSet_double&>( *hist_ );
      // Since Allocate1D only reserves data, use assignment op.
      dds = Bins_;
      hist_->SetDim(Dimension::X, dimensions_[0]);
    } else if (N_dimensions_ == 2) {
      DataSet_MatrixDbl& mds = static_cast<DataSet_MatrixDbl&>( *hist_ );
      mds.Allocate2D( dimensions_[0].Bins(), dimensions_[1].Bins() );
      std::copy( Bins_.begin(), Bins_.end(), mds.begin() );
      hist_->SetDim(Dimension::X, dimensions_[0]);
      hist_->SetDim(Dimension::Y, dimensions_[1]);
      outfile_->ProcessArgs("noxcol usemap nolabels");
    } else if (N_dimensions_ == 3) {
      DataSet_GridFlt& gds = static_cast<DataSet_GridFlt&>( *hist_ );
      //gds.Allocate3D( dimensions_[0].Bins(), dimensions_[1].Bins(), dimensions_[2].Bins() );
      gds.Allocate_N_O_D( dimensions_[0].Bins(), dimensions_[1].Bins(), dimensions_[2].Bins(),
                          Vec3(dimensions_[0].Min(), dimensions_[1].Min(), dimensions_[2].Min()),
                          Vec3(dimensions_[0].Step(), dimensions_[1].Step(), dimensions_[2].Step())
                        );
      //std::copy( Bins_.begin(), Bins_.end(), gds.begin() );
      // FIXME: Copy will not work since in grids data is ordered with Z
      // changing fastest. Should the ordering in grid be changed?
      size_t idx = 0;
      for (size_t z = 0; z < gds.NZ(); z++)
        for (size_t y = 0; y < gds.NY(); y++)
          for (size_t x = 0; x < gds.NX(); x++)
            gds.SetElement( x, y, z, (float)Bins_[idx++] );
      hist_->SetDim(Dimension::X, dimensions_[0]);
      hist_->SetDim(Dimension::Y, dimensions_[1]);
      hist_->SetDim(Dimension::Z, dimensions_[2]);
      outfile_->ProcessArgs("noxcol usemap nolabels");
      // Create pseudo-topology/trajectory
      if (!traj3dName_.empty()) {
        Topology pseudo;
        pseudo.AddTopAtom(Atom("H3D", 0), Residue("H3D", 1, ' ', ' '));
        pseudo.CommonSetup();
        if (!parmoutName_.empty()) {
          ParmFile pfile;
          if (pfile.WriteTopology( pseudo, parmoutName_, ParmFile::UNKNOWN_PARM, 0 ))
            mprinterr("Error: Could not write pseudo topology to '%s'\n", parmoutName_.c_str());
        }
        Trajout_Single out;
        if (out.PrepareTrajWrite(traj3dName_, ArgList(), &pseudo, CoordinateInfo(),
                                 Ndata, traj3dFmt_) == 0)
        {
          Frame outFrame(1);
          for (size_t i = 0; i < Ndata; ++i) {
            outFrame.ClearAtoms();
            outFrame.AddVec3( Vec3(histdata_[0]->Dval(i), 
                                   histdata_[1]->Dval(i), 
                                   histdata_[2]->Dval(i)) );
            out.WriteSingle(i, outFrame);
          }
          out.EndTraj();
        } else
          mprinterr("Error: Could not set up '%s' for write.\n", traj3dName_.c_str());
      }
    }
  }

  return Analysis::OK;
}