Ejemplo n.º 1
0
//static
LLVector2 LLUI::getWindowSize()
{
	LLCoordWindow window_rect;
	sWindow->getSize(&window_rect);

	return LLVector2(window_rect.mX / getScaleFactor().mV[VX], window_rect.mY / getScaleFactor().mV[VY]);
}
Ejemplo n.º 2
0
//static 
void LLUI::setMousePositionScreen(S32 x, S32 y)
{
	S32 screen_x, screen_y;
	screen_x = llround((F32)x * getScaleFactor().mV[VX]);
	screen_y = llround((F32)y * getScaleFactor().mV[VY]);
	
	LLView::getWindow()->setCursorPosition(LLCoordGL(screen_x, screen_y).convert());
}
Ejemplo n.º 3
0
//static 
void LLUI::getMousePositionScreen(S32 *x, S32 *y)
{
	LLCoordWindow cursor_pos_window;
	getWindow()->getCursorPosition(&cursor_pos_window);
	LLCoordGL cursor_pos_gl(cursor_pos_window.convert());
	*x = llround((F32)cursor_pos_gl.mX / getScaleFactor().mV[VX]);
	*y = llround((F32)cursor_pos_gl.mY / getScaleFactor().mV[VX]);
}
Ejemplo n.º 4
0
void ScaleX::execEvent()
{
  g_log.information("Processing event workspace");
  const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
  const std::string op = getPropertyValue("Operation");
  EventWorkspace_const_sptr inputWS=boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
  // generate the output workspace pointer
  API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
  EventWorkspace_sptr outputWS;
  if (matrixOutputWS == matrixInputWS)
    outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
  else
  {
    //Make a brand new EventWorkspace
    outputWS = boost::dynamic_pointer_cast<EventWorkspace>(API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
    //Copy geometry over.
    API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
    //You need to copy over the data as well.
    outputWS->copyDataFrom( (*inputWS) );
    //Cast to the matrixOutputWS and save it
    matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
    this->setProperty("OutputWorkspace", matrixOutputWS);
  }
  int numHistograms = static_cast<int>(inputWS->getNumberHistograms());
  PARALLEL_FOR1(outputWS)
  for (int i=0; i < numHistograms; ++i)
  {
    PARALLEL_START_INTERUPT_REGION
    //Do the offsetting
    if ((i >= m_wi_min) && (i <= m_wi_max))
    {
      if(op=="Multiply")
      {
        outputWS->getEventList(i).scaleTof(getScaleFactor(inputWS, i));
        if( m_algFactor < 0 )
        {
          outputWS->getEventList(i).reverse();
        }
      }
      else if(op=="Add")
      {
        outputWS->getEventList(i).addTof(getScaleFactor(inputWS, i));
      }
    }
    m_progress->report("Scaling X");
    PARALLEL_END_INTERUPT_REGION
  }
  PARALLEL_CHECK_INTERUPT_REGION
  outputWS->clearMRU();
}
Ejemplo n.º 5
0
    void ScalingLayer::renderToTarget(MyGUI::IRenderTarget *_target, bool _update)
    {
        MyGUI::IntSize globalViewSize = MyGUI::RenderManager::getInstance().getViewSize();
        MyGUI::IntSize viewSize = globalViewSize;
        float scale = getScaleFactor();
        viewSize.width /= scale;
        viewSize.height /= scale;

        float hoffset = (globalViewSize.width - mViewSize.width*getScaleFactor())/2.f / static_cast<float>(globalViewSize.width);
        float voffset = (globalViewSize.height - mViewSize.height*getScaleFactor())/2.f / static_cast<float>(globalViewSize.height);

        ProxyRenderTarget proxy(_target, viewSize, hoffset, voffset);

        MyGUI::OverlappedLayer::renderToTarget(&proxy, _update);
    }
Ejemplo n.º 6
0
/**
 * Handle pointer releases.
 * @param point The pointer position on the screen.
 */
void ScreenImageSwiper::handlePointerReleased(MAPoint2d point)
{
	// Search for the image on the center of the screen.
	int centeredImage = -1;
	for (int i = 0; i < mImagesSize; ++i)
	{
		if ( mImages[i]->isOnScreenCenter(mScreenWidth) )
		{
			centeredImage = i;
			break;
		}
	}

	// Align images to grid.
	if (centeredImage >= 0)
	{
		mLabelLayout->setText(mImages[centeredImage]->getName());
		int offset = mImages[centeredImage]->getGridOffset(mScreenWidth);
		for (int i = 0; i < mImagesSize; ++i)
		{
			mImages[i]->update(offset, 0);
		}
	}

	float scaleFactor = getScaleFactor();
	mPointerXStart = (int)((float) point.x * scaleFactor);
	mPointerXEnd = (int)((float) point.x * scaleFactor);
}
BOOL PieMenu::handleHover(S32 x, S32 y, MASK mask)
{
	// initialize pie scale factor for popup effect
	F32 factor = getScaleFactor();

	// initially, the current segment is marked as invalid
	mCurrentSegment = -1;

	// remember to take the UI scaling into account
	LLVector2 scale = gViewerWindow->getDisplayScale();
	// move mouse coordinates to be relative to the pie center
	LLVector2 mouseVector(x - PIE_OUTER_SIZE / scale.mV[VX], y - PIE_OUTER_SIZE / scale.mV[VY]);

	// get the distance from the center point
	F32 distance = mouseVector.length();

	// check if our mouse pointer is within the pie slice area
	if (distance > PIE_INNER_SIZE && (distance < (PIE_OUTER_SIZE * factor) || mFirstClick))
	{
		// get the angle of the mouse pointer from the center in radians
		F32 angle = acos(mouseVector.mV[VX] / distance);
		// if the mouse is below the middle of the pie, reverse the angle
		if (mouseVector.mV[VY] < 0)
		{
			angle = F_PI * 2 - angle;
		}
		// rotate the angle slightly so the slices' centers are aligned correctly
		angle += F_PI / 8;

		// calculate slice number from the angle
		mCurrentSegment = (S32) (8.f * angle / (F_PI * 2.f)) % 8;
	}

	return TRUE;
}
Ejemplo n.º 8
0
/**
 * Handle pointer presses.
 * @param point The pointer position on the screen.
 */
void ScreenImageSwiper::handlePointerPressed(MAPoint2d point)
{
	// Set start and end swipe point to the touch down point.

	float scaleFactor = getScaleFactor();
	mPointerXStart = (int)((float) point.x * scaleFactor);
	mPointerXEnd = (int)((float) point.x * scaleFactor);
}
Ejemplo n.º 9
0
NutrientAmount FoodAmount::getScaledCaloriesFromNutrientId
  (const QString& nutrId) const
{
  if (getFood() == NULL) {
    throw std::logic_error("Attempted to scale the nutrients of an undefined food.");
  }

  return getFood()->getCaloriesFromNutrientId(nutrId) * getScaleFactor();
}
Ejemplo n.º 10
0
void ImageEditor::cropImage(){
  if(selRect.isNull()){ return; }
  qreal sf = getScaleFactor();
  QRect srect = QRect( qRound(selRect.x()/sf), qRound(selRect.y()/sf), qRound(selRect.width()/sf), qRound(selRect.height()/sf));
  fullIMG = fullIMG.copy(srect);
  scaledIMG = fullIMG.scaled( defaultSize, Qt::KeepAspectRatio,Qt::SmoothTransformation);
  selRect = QRect();
  emit selectionChanged(false);
  this->update(); //trigger paint event
}
Ejemplo n.º 11
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ScaleVolume::readFilterParameters(AbstractFilterParametersReader* reader, int index)
{
  reader->openFilterGroup(this, index);
  setApplyToVoxelVolume( reader->readValue("ApplyToVoxelVolume", getApplyToVoxelVolume()) );
  setApplyToSurfaceMesh( reader->readValue("ApplyToSurfaceMesh", getApplyToSurfaceMesh()) );
  setScaleFactor( reader->readFloatVec3("ScaleFactor", getScaleFactor() ) );
  setDataContainerName(reader->readString("DataContainerName", getDataContainerName()));
  setSurfaceDataContainerName(reader->readString("SurfaceDataContainerName", getSurfaceDataContainerName()));
  reader->closeFilterGroup();
}
Ejemplo n.º 12
0
void
IntersectActor::setupChildrenPriorities(void)
{
    UInt32 numChildren      = getNumChildren     ();
    UInt32 numExtraChildren = getNumExtraChildren();

    Real32 scaleFactor      = getScaleFactor();
    Real32 hitDist          = getHitDistance();
    Real32 bvEnter;
    Real32 bvExit;

    setChildrenListEnabled(true);

    for(UInt32 i = 0; i < numChildren; ++i)
    {
#ifndef OSG_2_PREP
        const DynamicVolume &vol = getChild(i)->editVolume(true);
#else
        const BoxVolume     &vol = getChild(i)->editVolume(true);
#endif

        if((vol.intersect(getRay(), bvEnter, bvExit) == true   ) &&
           (bvEnter * scaleFactor                    <  hitDist)   )
        {
            setChildPriority(i, -bvEnter * scaleFactor);
        }
        else
        {
            setChildActive  (i, false);
        }
    }

    for(UInt32 i = 0; i < numExtraChildren; ++i)
    {
#ifndef OSG_2_PREP
        const DynamicVolume &vol = getChild(i)->editVolume(true);
#else
        const BoxVolume     &vol = getChild(i)->editVolume(true);
#endif

        if((vol.intersect(getRay(), bvEnter, bvExit) == true   ) &&
           (bvEnter * scaleFactor                    <  hitDist)   )
        {
            setExtraChildPriority(i, -bvEnter * scaleFactor);
        }
        else
        {
            setExtraChildActive  (i, false);
        }
    }
}
Ejemplo n.º 13
0
vgm::MatrixR Transform::gethMatrix() const
{
	vgm::MatrixR matrix;
	
	matrix.setTransform(
		getTranslation(),
		getRotation(),
		getScaleFactor(),
		getScaleOrientation(),
		getCenter()
		);
		
	return ( matrix );
}
Ejemplo n.º 14
0
void TmultiScore::resizeEvent(QResizeEvent* event) {
  int hh = height(), ww = width();
  if (event) {
    hh = event->size().height();
    ww = event->size().width();
  }
  if (m_inMode == e_single) {
    if (ww < 300 || hh < 200)
      return;
    TsimpleScore::resizeEvent(event);
  } else {
    if (ww < 400 || hh < 200)
      return;

    qreal factor = getScaleFactor(hh, m_scale);
    scoreScene()->prepareToChangeRect();
    scale(factor, factor);
    qreal oldStaffWidth = staff()->viewWidth();
    for (int i = 0; i < m_staves.size(); i++)
      adjustStaffWidth(m_staves[i]);

    if (oldStaffWidth != staff()->viewWidth()) {
    // TODO: another routine for non-rhythms
      for (int i = 0; i < m_staves.size(); i++) {
        qreal staffContentWidth = m_staves[i]->contentWidth(m_staves[i]->gapFactor());
        if (staffContentWidth != m_staves[i]->width()) {
          qDebug() << debug() << "staff width changed about" << qAbs(staffContentWidth - m_staves[i]->width()) << "- fitting";
          m_staves[i]->fit();
          m_staves[i]->updateNotesPos();
        }
      }
      for (int i = 0; i < m_staves.size(); i++) {
        if (m_staves[i]->count() == 0)
          deleteLastStaff();
      }
    }

    qreal staffOff = staff()->isPianoStaff() ? 1.1 : 0.0;
    for (int i = 0; i < m_staves.size(); i++) {
      if (i == 0)
        m_staves[i]->setPos(staffOff, 0.0);
      else
        m_staves[i]->setPos(staffOff, m_staves[i - 1]->pos().y() + m_staves[i - 1]->loNotePos() - m_staves[i]->hiNotePos() +
                            ((staff()->hasScordature() && i == 1) ? 7.0 : 4.0));
    }
    updateSceneRect();
  }
}
Ejemplo n.º 15
0
    void ScalingLayer::screenToLayerCoords(int& _left, int& _top) const
    {
        float scale = getScaleFactor();
        if (scale <= 0.f)
            return;

        MyGUI::IntSize globalViewSize = MyGUI::RenderManager::getInstance().getViewSize();

        _left -= globalViewSize.width/2;
        _top -= globalViewSize.height/2;

        _left /= scale;
        _top /= scale;

        _left += mViewSize.width/2;
        _top += mViewSize.height/2;
    }
Ejemplo n.º 16
0
QVector<FoodAmount> FoodAmount::getScaledComponents() const
{
  // See getScaledNutrients for logic description

  if (getFood() == NULL) {
    throw std::logic_error("Attempted to scale the components of an undefined food.");
  }

  QVector<FoodAmount> components = getFood()->getComponentAmounts();

  double scaleFactor = getScaleFactor();

  for (QVector<FoodAmount>::iterator i = components.begin(); i != components.end(); ++i)
  {
    (*i) *= scaleFactor;
  }

  return components;
}
Ejemplo n.º 17
0
QMap<QString, NutrientAmount> FoodAmount::getScaledNutrients() const
{
  // TODO: Cache this instead of recomputing every time

  if (getFood() == NULL) {
    throw std::logic_error("Attempted to scale the nutrients of an undefined food.");
  }

  QMap<QString, NutrientAmount> nutrients = getFood()->getNutrients();

  double scaleFactor = getScaleFactor();

  for (QMap<QString, NutrientAmount>::iterator i = nutrients.begin();
      i != nutrients.end(); ++i)
  {
    (*i) *= scaleFactor;
  }

  return nutrients;
}
Ejemplo n.º 18
0
//-----------------------------------------------------------------------------
void D2DDrawContext::drawBitmap (CBitmap* bitmap, const CRect& dest, const CPoint& offset, float alpha)
{
	if (renderTarget == 0)
		return;
	D2DApplyClip ac (this);
	if (ac.isEmpty ())
		return;
	
	double transformedScaleFactor = getScaleFactor ();
	CGraphicsTransform t = getCurrentTransform ();
	if (t.m11 == t.m22 && t.m12 == 0 && t.m21 == 0)
		transformedScaleFactor *= t.m11;
	IPlatformBitmap* platformBitmap = bitmap->getBestPlatformBitmapForScaleFactor (transformedScaleFactor);
	D2DBitmap* d2dBitmap = platformBitmap ? dynamic_cast<D2DBitmap*> (platformBitmap) : 0;
	if (d2dBitmap)
	{
		if (d2dBitmap->getSource ())
		{
			ID2D1Bitmap* d2d1Bitmap = D2DBitmapCache::instance ()->getBitmap (d2dBitmap, renderTarget);
			if (d2d1Bitmap)
			{
				double bitmapScaleFactor = platformBitmap->getScaleFactor ();
				CGraphicsTransform bitmapTransform;
				bitmapTransform.scale (bitmapScaleFactor, bitmapScaleFactor);
				Transform transform (*this, bitmapTransform.inverse ());

				CRect d (dest);
				d.makeIntegral ();
				CRect source (dest);
				source.offset (-source.left, -source.top);
				source.offset (offset.x, offset.y);

				bitmapTransform.transform (source);

				D2D1_RECT_F sourceRect = makeD2DRect (source);
				renderTarget->DrawBitmap (d2d1Bitmap, makeD2DRect (d), alpha * currentState.globalAlpha, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &sourceRect);
			}
		}
	}
}
Ejemplo n.º 19
0
    /**
     * Updates the bounding volumes of a model. In this case the OOBB
     * is used to speed up the calculation of the bounding sphere and the
     * AABB
     *
     * Fast calculation idea copied from
     *    http://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
     */
    void _updateBoundingVolumes()
    {
        glm::mat4 model = getModelMatrix();
        glm::mat4 absModel(glm::abs(model[0][0]), glm::abs(model[0][1]), glm::abs(model[0][2]), glm::abs(model[0][3]),
                           glm::abs(model[1][0]), glm::abs(model[1][1]), glm::abs(model[1][2]), glm::abs(model[1][3]),
                           glm::abs(model[2][0]), glm::abs(model[2][1]), glm::abs(model[2][2]), glm::abs(model[2][3]),
                           glm::abs(model[3][0]), glm::abs(model[3][1]), glm::abs(model[3][2]), glm::abs(model[3][3]));

        glm::vec3 center = (_oobb.getMin() + _oobb.getMax()) / 2.0f;
        glm::vec3 extent = (_oobb.getMax() - _oobb.getMin()) / 2.0f;

        glm::vec3 newCenter = glm::vec3(model * glm::vec4(center, 1.0f));
        glm::vec3 newExtent = glm::vec3(absModel * glm::vec4(extent, 0.0f));

        glm::vec3 min = newCenter - newExtent;
        glm::vec3 max = newCenter + newExtent;

        _aabb.setMin(newCenter - newExtent);
        _aabb.setMax(newCenter + newExtent);

        _boundingSphere.setRadius(glm::length(_maxLengthVertex * getScaleFactor()));
    }
Ejemplo n.º 20
0
void ImageEditor::scaleDown(int val){
  qreal sf = getScaleFactor();
  sf-= ((qreal) val)/100.0;
  if(sf<0.1){ sf = 0.1; }
  rescaleImage(sf);
}
Ejemplo n.º 21
0
Archivo: main.cpp Proyecto: jhasse/jngl
void translate(const double x, const double y) {
    opengl::translate(x * getScaleFactor(), y * getScaleFactor());
}
Ejemplo n.º 22
0
//static
void LLUI::screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y)
{
	*gl_x = llround((F32)screen_x * getScaleFactor().mV[VX]);
	*gl_y = llround((F32)screen_y * getScaleFactor().mV[VY]);
}
Ejemplo n.º 23
0
//static
void LLUI::glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y)
{
	*screen_x = llround((F32)gl_x / getScaleFactor().mV[VX]);
	*screen_y = llround((F32)gl_y / getScaleFactor().mV[VY]);
}
Ejemplo n.º 24
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ScaleVolume::setupFilterParameters()
{
  FilterParameterVector parameters;

  parameters.push_back(FloatVec3FilterParameter::New("Scaling Factor", "ScaleFactor", getScaleFactor(), FilterParameter::Parameter));

  QStringList linkedProps("DataContainerName");
  parameters.push_back(LinkedBooleanFilterParameter::New("Apply to Image Geometry", "ApplyToVoxelVolume", getApplyToVoxelVolume(), linkedProps, FilterParameter::Parameter));
  {
    DataContainerSelectionFilterParameter::RequirementType req;
    req.dcGeometryTypes = QVector<unsigned int>(1, DREAM3D::GeometryType::ImageGeometry);
    parameters.push_back(DataContainerSelectionFilterParameter::New("Data Container Image Geometry to Scale", "DataContainerName", getDataContainerName(), FilterParameter::RequiredArray, req));
  }
  linkedProps.clear();
  linkedProps << "SurfaceDataContainerName";
  parameters.push_back(LinkedBooleanFilterParameter::New("Apply to Surface Geometry", "ApplyToSurfaceMesh", getApplyToSurfaceMesh(), linkedProps, FilterParameter::Parameter));
  {
    DataContainerSelectionFilterParameter::RequirementType req;
    QVector<unsigned int> dcGeometryTypes;
    dcGeometryTypes.push_back(DREAM3D::GeometryType::TriangleGeometry);
    dcGeometryTypes.push_back(DREAM3D::GeometryType::QuadGeometry);
    req.dcGeometryTypes = dcGeometryTypes;
    parameters.push_back(DataContainerSelectionFilterParameter::New("Data Container Surface Geometry to Scale", "SurfaceDataContainerName", getSurfaceDataContainerName(), FilterParameter::RequiredArray, req));
  }

  setFilterParameters(parameters);
}
Ejemplo n.º 25
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void ScaleVolume::setupFilterParameters()
{
  FilterParameterVector parameters;

  parameters.push_back(FloatVec3FilterParameter::New("Scaling Factor", "ScaleFactor", getScaleFactor(), FilterParameter::Parameter));

  QStringList linkedProps("DataContainerName");
  parameters.push_back(LinkedBooleanFilterParameter::New("Apply to Image Geometry", "ApplyToVoxelVolume", getApplyToVoxelVolume(), linkedProps, FilterParameter::Parameter));
  parameters.push_back(DataContainerSelectionFilterParameter::New("Data Container Image Geometry to Scale", "DataContainerName", getDataContainerName(), FilterParameter::RequiredArray));
  linkedProps.clear();
  linkedProps << "SurfaceDataContainerName";
  parameters.push_back(LinkedBooleanFilterParameter::New("Apply to Surface Geometry", "ApplyToSurfaceMesh", getApplyToSurfaceMesh(), linkedProps, FilterParameter::Parameter));
  parameters.push_back(DataContainerSelectionFilterParameter::New("Data Container Surface Geometry to Scale", "SurfaceDataContainerName", getSurfaceDataContainerName(), FilterParameter::RequiredArray));

  setFilterParameters(parameters);
}
cv::Mat motionEstimation_node::imageCallback(sensor_msgs::ImagePtr &left, sensor_msgs::ImagePtr &right)
{
   /* try
    {
        cv::imshow("left", cv_bridge::toCvShare(left, "bgr8")->image);
        cv::imshow("right", cv_bridge::toCvShare(right, "bgr8")->image);
        cv::waitKey(30);
    }*/
      if(image_sub_count == 0)
        {

        //right;
          features = getStrongFeaturePoints(image_L1, 100, 0.001, 20);

          refindFeaturePoints(left, right, features, points_L1_temp, points_R1_temp);
           if (10 > points_L1_temp.size())
           {
               ROS_INFO("Could not find more than features in stereo 1:");
           }
           else
           {
               camera.left = left;
               camera.right = right;
               cam.push_back(camera);

           }

        }

       image_sub_count++;

      while(image_sub_count > 0)
      {
              skipFrameNumber++;
          if(4 < skipFrameNumber)
          {
             ROS_INFO("NO MOVEMENT FOR LAST 4 FRAMES");
             image_sub_count = 0;
             break;
          }
          refindFeaturePoints(camera.left, left, points_L1_temp, points_L1, points_L2);
          refindFeaturePoints(camera.right, right, points_R1_temp, points_R1, points_R2);
          deleteUnvisiblePoints(points_L1_temp, points_R1_temp, points_L1, points_R1, points_L2, points_R2, camera.left.cols, camera.left.rows);

          if(0 == points_L1.size())
          {
              image_sub_count--;
              ROS_INFO("Could not find more than features in stereo 2:");
              break;
          }

          if (1 == mode)
          {
             if (8 > points_L1.size())
             {
                ROS_INFO("NO MOVEMENT: to less points found");
                image_sub_count--;
                break;
             }

             getInliersFromHorizontalDirection(make_pair(points_L1, points_R1), inliersHorizontal_L1, inliersHorizontal_R1);
             getInliersFromHorizontalDirection(make_pair(points_L2, points_R2), inliersHorizontal_L2, inliersHorizontal_R2);
             deleteZeroLines(points_L1, points_R1, points_L2, points_R2, inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2);

             if (8 > inliersHorizontal_L1.size())
             {
                ROS_INFO("NO MOVEMENT: couldn't find horizontal points... probably rectification fails or to less feature points found?!");
                image_sub_count--;
                break;
             }

            foundF_L = getFundamentalMatrix(points_L1, points_L2, &inliersF_L1, &inliersF_L2, F_L);
            foundF_R = getFundamentalMatrix(points_R1, points_R2, &inliersF_R1, &inliersF_R2, F_R);
            deleteZeroLines(inliersF_L1, inliersF_L2, inliersF_R1, inliersF_R2);

            if (1 > inliersF_L1.size())
            {
                ROS_INFO("NO MOVEMENT: couldn't find enough ransac inlier");
                image_sub_count--;
                break;
            }

            drawCorresPoints(camera.left, inliersF_L1, inliersF_L2, "inlier F left " , CV_RGB(0,0,255));
            drawCorresPoints(camera.right, inliersF_R1, inliersF_R2, "inlier F right " , CV_RGB(0,0,255));
            bool poseEstimationFoundES_L = false;
            bool poseEstimationFoundES_R = false;

            if(foundF_L)
            {
              poseEstimationFoundES_L = motionEstimationEssentialMat(inliersF_L1, inliersF_L2, F_L, K_L, T_E_L, R_E_L);
            }

            if(foundF_R)
            {
              poseEstimationFoundES_R = motionEstimationEssentialMat(inliersF_R1, inliersF_R2, F_R, K_R, T_E_R, R_E_R);
            }

            if (!poseEstimationFoundES_L && !poseEstimationFoundES_R)
            {
               image_sub_count--;
               break;
               T_E_L = cv::Mat::zeros(3, 1, CV_32F);
               R_E_L = cv::Mat::eye(3, 3, CV_32F);
               T_E_R = cv::Mat::zeros(3, 1, CV_32F);
               R_E_R = cv::Mat::eye(3, 3, CV_32F);
            }

            else if (!poseEstimationFoundES_L)
            {
               T_E_L = cv::Mat::zeros(3, 1, CV_32F);
               R_E_L = cv::Mat::eye(3, 3, CV_32F);
            }

            else if (!poseEstimationFoundES_R)
            {
               T_E_R = cv::Mat::zeros(3, 1, CV_32F);
               R_E_R = cv::Mat::eye(3, 3, CV_32F);
            }

            cv::Mat PK_0 = K_L * P_0;
            cv::Mat PK_LR = K_R * P_LR;

            TriangulatePointsHZ(PK_0, PK_LR, points_L1, points_R1, 0, pointCloud_1);
            TriangulatePointsHZ(PK_0, PK_LR, points_L2, points_R2, 0, pointCloud_2);
#if 1
            composeProjectionMat(T_E_L, R_E_L, P_L);
            composeProjectionMat(T_E_R, R_E_R, P_R);
            cv::Mat PK_L = K_L * P_L;
            cv::Mat PK_R = K_R * P_R;
            getScaleFactor(PK_0, PK_LR, PK_L, PK_R, points_L1, points_R1, points_L2, points_R2, u_L1, u_R1, stereoCloud, nearestPoints);
            ROS_INFO( "skipFrameNumber :  %d",  skipFrameNumber);
            if(u_L1 < -1 || u_L1 > 1000*skipFrameNumber)
            {
               ROS_INFO("scale factors for left cam is too big: %d ", u_L1);
               //skipFrame = true;
               //continue;
            }
            else
            {
                T_E_L = T_E_L * u_L1;
            }

            if(u_R1 < -1 || u_R1 > 1000*skipFrameNumber )
            {
                ROS_INFO( "scale factors for right cam is too big: %d ", u_R1);
                                //skipFrame = true;
                                //continue;
            }
            else
            {
                T_E_R = T_E_R * u_R1;
            }

#if 0
                // get RGB values for pointcloud representation
                std::vector<cv::Vec3b> RGBValues;
                for (unsigned int i = 0; i < points_L1.size(); ++i){
                    uchar grey = camera.left.at<uchar>(points_L1[i].x, points_L1[i].y);
                    RGBValues.push_back(cv::Vec3b(grey,grey,grey));
                }

                std::vector<cv::Vec3b> red;
                for (unsigned int i = 0; i < 5; ++i){
                    red.push_back(cv::Vec3b(0,0,255));
                }

                AddPointcloudToVisualizer(stereoCloud, "cloud1" + std::to_string(frame1), RGBValues);
                AddPointcloudToVisualizer(nearestPoints, "cloud2" + std::to_string(frame1), red);
#endif
#else
                // 2. method:
                float u_L2, u_R2;
                getScaleFactor2(T_LR, R_LR, T_E_L, R_E_L, T_E_R, u_L2, u_R2);

                if(u_L2 < -1000 || u_R2 < -1000 || u_L2 > 1000 || u_R2 > 1000 ){
                    std::cout << "scale factors to small or to big:  L: " << u_L2 << "  R: " << u_R2  << std::endl;
                } else {
                    T_E_L = T_E_L * u_L2;
                    T_E_R = T_E_R * u_R2;
                }

                //compare both methods
                ROS_INFO("u links  2:%d ", u_L2);
                ROS_INFO("u rechts 2:%d", u_R2);
#endif
                ROS_INFO("translation 1:%d ", T_E_L);
                cv::Mat newTrans3D_E_L;
                getNewTrans3D( T_E_L, R_E_L, newTrans3D_E_L);


                cv::Mat newPos_ES_L;
                getAbsPos(currentPos_ES_L, newTrans3D_E_L, R_E_L.t(), newPos_ES_L);
                cv::Mat rotation_ES_L, translation_ES_L;
                decomposeProjectionMat(newPos_ES_L, translation_ES_L, rotation_ES_L);
                cv::Mat newPos_ES_mean = newPos_ES_L + newPos_ES_R;
                newPos_ES_mean /= 2;

                cv::Mat rotation_ES_mean, translation_ES_mean;
                decomposeProjectionMat(newPos_ES_mean, translation_ES_mean, rotation_ES_mean);
                geometry_msgs::Pose pose;
                pose.position.x = rotation_ES_mean(0);
                pose.position.y = rotation_ES_mean(1);
                pose.position.z = rotation_ES_mean(2);
                 posePublisher_.publish(pose);
                Eigen::Matrix3f m;
                m = translation_ES_mean;
                float roll;
                float pitch;
                float yaw;
                roll = atan2(m(3,2), m(3,3));
                pitch = atan(-m(3,1)/(m(3,2)*sin(roll)+m(3,3)*cos(roll)));
                yaw = atan2(m(2,1),m(1,1));

                currentPos_ES_mean = newPos_ES_mean;
                currentPos_ES_L = newPos_ES_L;
                currentPos_ES_R = newPos_ES_R;

                ROS_INFO("abs. position  ", translation_ES_mean);


                

          }

          if(2 == mode)
          {
              if (8 > points_L1.size())
              {
                  ROS_INFO("NO MOVEMENT: to less points found");
                  image_sub_count--;
                  break;
              }

              std::vector<cv::Point2f> inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2;
              getInliersFromHorizontalDirection(make_pair(points_L1, points_R1), inliersHorizontal_L1, inliersHorizontal_R1);
              getInliersFromHorizontalDirection(make_pair(points_L2, points_R2), inliersHorizontal_L2, inliersHorizontal_R2);
              //delete all points that are not correctly found in stereo setup
              deleteZeroLines(points_L1, points_R1, points_L2, points_R2, inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2);

              if (8 > points_L1.size())
              {
                   ROS_INFO("NO MOVEMENT: couldn't find horizontal points... probably rectification fails or to less feature points found?!");
                   image_sub_count--;
                   break;
              }

              cv::Mat F_L;
              bool foundF_L;
              std::vector<cv::Point2f> inliersF_L1, inliersF_L2;
              foundF_L = getFundamentalMatrix(points_L1, points_L2, &inliersF_L1, &inliersF_L2, F_L);

              // compute fundemental matrix F_R1R2 and get inliers from Ransac
              cv::Mat F_R;
              bool foundF_R;
              std::vector<cv::Point2f> inliersF_R1, inliersF_R2;
              foundF_R = getFundamentalMatrix(points_R1, points_R2, &inliersF_R1, &inliersF_R2, F_R);

              // make sure that there are all inliers in all frames.
              deleteZeroLines(inliersF_L1, inliersF_L2, inliersF_R1, inliersF_R2);

              drawCorresPoints(image_R1, inliersF_R1, inliersF_R2, "inlier F right " , CV_RGB(0,0,255));
              drawCorresPoints(image_L1, inliersF_L1, inliersF_L2, "inlier F left " , CV_RGB(0,0,255));

              // calibrate projection mat
              cv::Mat PK_0 = K_L * P_0;
              cv::Mat PK_LR = K_R * P_LR;

              std::vector<cv::Point3f> pointCloud_1, pointCloud_2;
              TriangulatePointsHZ(PK_0, PK_LR, inliersF_L1, inliersF_R1, 0, pointCloud_1);
              TriangulatePointsHZ(PK_0, PK_LR, inliersF_L2, inliersF_R2, 0, pointCloud_2);

#if 1
                //LEFT:
                bool poseEstimationFoundTemp_L = false;
                cv::Mat T_PnP_L, R_PnP_L;
                if(foundF_L){
                    // GUESS TRANSLATION + ROTATION UP TO SCALE!!!
                    poseEstimationFoundTemp_L = motionEstimationEssentialMat(inliersF_L1, inliersF_L2, F_L, K_L, T_PnP_L, R_PnP_L);
                }

                if (!poseEstimationFoundTemp_L){
                    image_sub_count--;
                    break;
                }

#if 0
                // scale factor:
                float u_L1;
                cv::Mat P_L;
                composeProjectionMat(T_PnP_L, R_PnP_L, P_L);

                // calibrate projection mat
                cv::Mat PK_L = K_L * P_L;

                getScaleFactorLeft(PK_0, PK_LR, PK_L, inliersF_L1, inliersF_R1, inliersF_L2, u_L1);
                if(u_L1 < -1 || u_L1 > 1000 ){
                    ROS_INFO("scale factors to small or to big:  L: ", u_L1);
                    image_sub_count--;
                    break;
                }

                T_PnP_L = T_PnP_L * u_L1;
#endif

                bool poseEstimationFoundPnP_L = motionEstimationPnP(inliersF_L2, pointCloud_1, K_L, T_PnP_L, R_PnP_L);

                if (!poseEstimationFoundPnP_L)
                {
                      image_sub_count--;
                      break;
                }

                if(cv::norm(T_PnP_L) > 1500.0 * skipFrameNumber)
                {
                  // this is bad...
                  ROS_INFO("NO MOVEMENT: estimated camera movement is too big, skip this camera.. T = ", cv::norm(T_PnP_L));
                  image_sub_count--;
                  break;
                }

                cv::Mat newTrans3D_PnP_L;
                getNewTrans3D( T_PnP_L, R_PnP_L, newTrans3D_PnP_L);

                cv::Mat newPos_PnP_L;
                getAbsPos(currentPos_PnP_L, newTrans3D_PnP_L, R_PnP_L, newPos_PnP_L);

                cv::Mat rotation_PnP_L, translation_PnP_L;
                decomposeProjectionMat(newPos_PnP_L, translation_PnP_L, rotation_PnP_L);

                pose.position.x = rotation_PnP_L(0);
                pose.position.y = rotation_PnP_L(1);
                pose.position.z = rotation_PnP_L(2);
                posePublisher_.publish(pose);
                Eigen::Matrix3f m;
                m = translation_ES_mean;
                float roll;
                float pitch;
                float yaw;
                roll = atan2(m(3,2), m(3,3));
                pitch = atan(-m(3,1)/(m(3,2)*sin(roll)+m(3,3)*cos(roll)));
                yaw = atan2(m(2,1),m(1,1));
                currentPos_PnP_L  = newPos_PnP_L ;
#else
              //RIGHT:
                             bool poseEstimationFoundTemp_R = false;
                             cv::Mat  T_PnP_R, R_PnP_R;
                             if(foundF_R){
                                 // GUESS TRANSLATION + ROTATION UP TO SCALE!!!
                                 poseEstimationFoundTemp_R = motionEstimationEssentialMat(inliersF_R1, inliersF_R2, F_R, K_R, KInv_R, T_PnP_R, R_PnP_R);
                             }

                             if (!poseEstimationFoundTemp_R){
                                 skipFrame = true;
                                 continue;
                             }

                             // use initial guess values for pose estimation
                             bool poseEstimationFoundPnP_R = motionEstimationPnP(inliersF_R2, pointCloud_1, K_R, T_PnP_R, R_PnP_R);

                             if (!poseEstimationFoundPnP_R){
                                 skipFrame = true;
                                 continue;
                             }

                             cv::Mat newTrans3D_PnP_R;
                             getNewTrans3D( T_PnP_R, R_PnP_R, newTrans3D_PnP_R);

                             cv::Mat newPos_PnP_R;
                             getAbsPos(currentPos_PnP_R, newTrans3D_PnP_R, R_PnP_R, newPos_PnP_R);

                             cv::Mat rotation_PnP_R, translation_PnP_R;
                             decomposeProjectionMat(newPos_PnP_R, translation_PnP_R, rotation_PnP_R);
                             pose.position.x = rotation_PnP_R(0);
                             pose.position.y = rotation_PnP_R(1);
                             pose.position.z = rotation_PnP_R(2);
                             posePublisher_.publish(pose);
                             Eigen::Matrix3f m;
                             m = translation_ES_mean;
                             float roll;
                             float pitch;
                             float yaw;
                             roll = atan2(m(3,2), m(3,3));
                             pitch = atan(-m(3,1)/(m(3,2)*sin(roll)+m(3,3)*cos(roll)));
                             yaw = atan2(m(2,1),m(1,1));
                             currentPos_PnP_R  = newPos_PnP_R ;
#endif
          }

                             if (3 == mode)
                             {
                                 std::vector<cv::Point2f> inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2;
                                 getInliersFromHorizontalDirection(make_pair(points_L1, points_R1), inliersHorizontal_L1, inliersHorizontal_R1);
                                 getInliersFromHorizontalDirection(make_pair(points_L2, points_R2), inliersHorizontal_L2, inliersHorizontal_R2);
                                 //delete all points that are not correctly found in stereo setup
                                 deleteZeroLines(points_L1, points_R1, points_L2, points_R2, inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2);

                                 if (8 > points_L1.size())
                                 {
                                     ROS_INFO("NO MOVEMENT: couldn't find horizontal points... probably rectification fails or to less feature points found?!");
                                     image_sub_count--;
                                     break;
                                 }

                                 drawCorresPoints(image_L1, points_L1, points_R1, "inlier F1 links rechts", cv::Scalar(255,255,0));
                                 drawCorresPoints(image_L2, points_L2, points_R2, "inlier F2 links rechts", cv::Scalar(255,255,0));

                                                // calibrate projection mat
                                 cv::Mat PK_0 = K_L * P_0;
                                 cv::Mat PK_LR = K_R * P_LR;

                                                // TRIANGULATE POINTS
                                 std::vector<cv::Point3f> pointCloud_1, pointCloud_2;
                                 TriangulatePointsHZ(PK_0, PK_LR, points_L1, points_R1, 0, pointCloud_1);
                                 TriangulatePointsHZ(PK_0, PK_LR, points_L2, points_R2, 0, pointCloud_2);


                                 float reproj_error_1L = calculateReprojectionErrorHZ(PK_0, points_L1, pointCloud_1);
                                 float reproj_error_1R = calculateReprojectionErrorHZ(PK_LR, points_R1, pointCloud_1);

                                 if (!positionCheck(P_0, pointCloud_2) && !positionCheck(P_LR, pointCloud_2) && reproj_error_2L < 10.0 && reproj_error_2R < 10.0 )
                                 {
                                        ROS_INFO("second pointcloud seem's to be not perfect..");
                                        image_sub_count--;
                                        break;
                                 }

#if 0
                //load disparity map
                cv::Mat dispMap1;
                cv::FileStorage fs_dist1(dataPath + "disparity/disparity_"+to_string(frame)+".yml", cv::FileStorage::READ);
                fs_dist1["disparity"] >> dispMap1;
                fs_dist1.release();

                cv::Mat dispMap2;
                cv::FileStorage fs_dist2(dataPath + "disparity/disparity_"+to_string(frame+1)+".yml", cv::FileStorage::READ);
                fs_dist2["disparity"] >> dispMap2;
                fs_dist2.release();

                dispMap1.convertTo(dispMap1, CV_32F);
                dispMap2.convertTo(dispMap2, CV_32F);

                std::vector <cv::Mat_<float>> cloud1;
                std::vector <cv::Mat_<float>> cloud2;
                for(unsigned int i = 0; i < inlier_median_L1.size(); ++i){
                    cv::Mat_<float> point3D1(1,4);
                    cv::Mat_<float> point3D2(1,4);
                    calcCoordinate(point3D1, Q, dispMap1, inlier_median_L1[i].x, inlier_median_L1[i].y);
                    calcCoordinate(point3D2, Q, dispMap2, inlier_median_L2[i].x, inlier_median_L2[i].y);
                    cloud1.push_back(point3D1);
                    cloud2.push_back(point3D2);
                }

                std::vector<cv::Point3f> pcloud1, pcloud2;
                std::vector<cv::Vec3b> rgb1, rgb2;
                for (unsigned int i = 0; i < cloud1.size(); ++i) {
                    if (!cloud1[i].empty() && !cloud2[i].empty()){
                        pcloud1.push_back(cv::Point3f(cloud1[i](0), cloud1[i](1), cloud1[i](2) ));
                                          pcloud2.push_back(cv::Point3f(cloud2[i](0), cloud2[i](1), cloud2[i](2) ));
                                                            rgb1.push_back(cv::Vec3b(255,0,0));
                                          rgb2.push_back(cv::Vec3b(0,255,0));
                    }
                }

                AddPointcloudToVisualizer(pcloud1, "pcloud1", rgb1);
                AddPointcloudToVisualizer(pcloud2, "pcloud2", rgb2);

                cv::Mat T_Stereo, R_Stereo;
                bool poseEstimationFoundStereo = motionEstimationStereoCloudMatching(pcloud1, pcloud2, T_Stereo, R_Stereo);

#else

                cv::Mat T_Stereo, R_Stereo;
                bool poseEstimationFoundStereo = motionEstimationStereoCloudMatching(pointCloud_1, pointCloud_2, T_Stereo, R_Stereo);
#endif

                if (!poseEstimationFoundStereo)
                {
                      image_sub_count--;
                      break;
                }
                ROS_INFO("ROTATION \n");
                ROS_INFO(R_Stereo);
                ROS_INFO("\n TRANSLATION \n");
                ROS_INFO(T_Stereo);

                float x_angle, y_angle, z_angle;
                decomposeRotMat(R_Stereo, x_angle, y_angle, z_angle);
                ROS_INFO("x angle:", x_angle);
                ROS_INFO("y angle:", y_angle);
                ROS_INFO("z angle:", z_angle);

                cv::Mat newTrans3D_Stereo;
                getNewTrans3D( T_Stereo, R_Stereo, newTrans3D_Stereo);

                cv::Mat newPos_Stereo;
                getAbsPos(currentPos_Stereo, newTrans3D_Stereo, R_Stereo, newPos_Stereo);

                cv::Mat rotation, translation;
                decomposeProjectionMat(newPos_Stereo, translation, rotation);

                pose.position.x = rotation(0);
                pose.position.y = rotation(1);
                pose.position.z = rotation(2);
                posePublisher_.publish(pose);
                Eigen::Matrix3f m;
                m = translation;
                float roll;
                float pitch;
                float yaw;
                roll = atan2(m(3,2), m(3,3));
                pitch = atan(-m(3,1)/(m(3,2)*sin(roll)+m(3,3)*cos(roll)));
                yaw = atan2(m(2,1),m(1,1));

                currentPos_Stereo = newPos_Stereo;



                             }

                             if (4 == mode)

                             {
                                             // ######################## TRIANGULATION TEST ################################
                                             // get inlier from stereo constraints
                                             std::vector<cv::Point2f> inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2;
                                             getInliersFromHorizontalDirection(make_pair(points_L1, points_R1), inliersHorizontal_L1, inliersHorizontal_R1);
                                             getInliersFromHorizontalDirection(make_pair(points_L2, points_R2), inliersHorizontal_L2, inliersHorizontal_R2);
                                             //delete all points that are not correctly found in stereo setup
                                             deleteZeroLines(points_L1, points_R1, points_L2, points_R2, inliersHorizontal_L1, inliersHorizontal_R1, inliersHorizontal_L2, inliersHorizontal_R2);

                                             drawCorresPoints(image_L1, points_L1, points_R1, "inlier 1 " , CV_RGB(0,0,255));
                                             drawCorresPoints(image_R1, points_L2, points_R2, "inlier 2 " , CV_RGB(0,0,255));

                                             if(0 == points_L1.size()){
                                                 image_sub_count--;
                                                 break;
                                             }

                                             // calibrate projection mat
                                             cv::Mat PK_0 = K_L * P_0;
                                             cv::Mat PK_LR = K_R * P_LR;

                                             std::vector<cv::Point3f> pointCloud_1, pointCloud_2;
                                             TriangulatePointsHZ(PK_0, PK_LR, points_L1, points_R1, 0, pointCloud_1);
                                             TriangulatePointsHZ(PK_0, PK_LR, points_L2, points_R2, 0, pointCloud_2);



                                             if(0 == pointCloud_1.size())
                                             {
                                                  ROS_INFO("horizontal inlier: can't find any corresponding points in all 4 frames' ");
                                                  image_sub_count--;
                                                  break;
                                             }


                                                             // get RGB values for pointcloud representation
                                              std::vector<cv::Vec3b> RGBValues;
                                              for (unsigned int i = 0; i < points_L1.size(); ++i)
                                              {
                                                   uchar grey = image_L1.at<uchar>(points_L1[i].x, points_L1[i].y);
                                                   RGBValues.push_back(cv::Vec3b(grey,grey,grey));
                                              }

                                                   AddPointcloudToVisualizer(pointCloud_1, "cloud1" + std::to_string(frame1), RGBValues);

#if 1
                                             //                int index = 0;
                                             //                for (auto i : pointCloud_1) {
                                             //                    float length = sqrt( i.x*i.x + i.y*i.y + i.z*i.z);
                                             //                    cout<< "HZ:  "<< index << ":  " << i << "   length: " << length << endl;
                                             //                    ++index;
                                             //                }
                                                   std::vector<cv::Point3f> pcloud_CV;
                                                   TriangulateOpenCV(PK_0, PK_LR, points_L1, points_R1, pcloud_CV);

                                             //                index = 0;
                                             //                for (auto i : pcloud_CV) {
                                             //                    float length = sqrt( i.x*i.x + i.y*i.y + i.z*i.z);
                                             //                    cout<< "CV:  "<< index << ":  " << i << "   length: " << length << endl;
                                             //                    ++index;
                                             //                }
                                                             std::vector<cv::Vec3b> RGBValues2;
                                                             for (unsigned int i = 0; i < points_L1.size(); ++i){
                                                                 //uchar grey2 = image_L2.at<uchar>(points_L2[i].x, points_L2[i].y);
                                                                 //RGBValues2.push_back(cv::Vec3b(grey2,grey2,grey2));
                                                                 RGBValues2.push_back(cv::Vec3b(255,0,0));
                                                             }

                                                             AddPointcloudToVisualizer(pcloud_CV, "cloud2" + std::to_string(frame1), RGBValues2);
#endif



          }


      }
Ejemplo n.º 27
0
//---------------------------------------------------------------------------
void GameCamera::render(void)
{
	//------------------------------------------------------
	// At present, these actually draw.  Later they will
	// add elements to the draw list and sort and draw.
	// The later time has arrived.  We begin sorting immediately.
	// NO LONGER NEED TO SORT!
	// ZBuffer time has arrived.  Share and Enjoy!
	// Everything SIMPLY draws at the execution point into the zBuffer
	// at the correct depth.  Miracles occur at that point!
	// Big code change but it removes a WHOLE bunch of code and memory!
	//--------------------------------------------------------
	// Get new viewport values to scale stuff.  No longer uses
	// VFX stuff for this.  ALL GOS NOW!
	gos_GetViewport(&viewMulX, &viewMulY, &viewAddX, &viewAddY);
	MidLevelRenderer::MLRState default_state;
	default_state.SetBackFaceOn();
	default_state.SetDitherOn();
	default_state.SetTextureCorrectionOn();
	default_state.SetZBufferCompareOn();
	default_state.SetZBufferWriteOn();
	default_state.SetFilterMode(MidLevelRenderer::MLRState::BiLinearFilterMode);
	float z = 1.0f;
	Stuff::RGBAColor fColor;
	fColor.red   = ((fogColor >> 16) & 0xff);
	fColor.green = ((fogColor >> 8) & 0xff);
	fColor.blue  = ((fogColor)&0xff);
	//--------------------------------------------------------
	// Get new viewport values to scale stuff.  No longer uses
	// VFX stuff for this.  ALL GOS NOW!
	screenResolution.x = viewMulX;
	screenResolution.y = viewMulY;
	calculateProjectionConstants();
	TG_Shape::SetViewport(viewMulX, viewMulY, viewAddX, viewAddY);
	userInput->setViewport(viewMulX, viewMulY, viewAddX, viewAddY);
	gos_TextSetRegion(viewAddX, viewAddY, viewMulX, viewMulY);
	//--------------------------------------------------------
	// Get new viewport values to scale stuff.  No longer uses
	// VFX stuff for this.  ALL GOS NOW!
	screenResolution.x = viewMulX;
	screenResolution.y = viewMulY;
	calculateProjectionConstants();
	globalScaleFactor = getScaleFactor();
	globalScaleFactor *= viewMulX / 640.0; // Scale Mechs to ScreenRES
	//-----------------------------------------------
	// Set Ambient for this pass of rendering
	uint32_t lightRGB = (ambientRed << 16) + (ambientGreen << 8) + ambientBlue;
	eye->setLightColor(1, lightRGB);
	eye->setLightIntensity(1, 1.0);
	MidLevelRenderer::PerspectiveMode = usePerspective;
	theClipper->StartDraw(cameraOrigin, cameraToClip, fColor, &fColor, default_state, &z);
	MidLevelRenderer::GOSVertex::farClipReciprocal =
		(1.0f - cameraToClip(2, 2)) / cameraToClip(3, 2);
	if (active && turn > 1)
	{
		//----------------------------------------------------------
		// Turn stuff on line by line until perspective is working.
		if (Environment.Renderer != 3)
			theSky->render(1);
		land->render(); // render the Terrain
		if (Environment.Renderer != 3)
			craterManager->render();			 // render the craters and footprints
		ObjectManager->render(true, true, true); // render all other objects
		land->renderWater();					 // Draw Water Last!
		if (useShadows && Environment.Renderer != 3)
			ObjectManager->renderShadows(true, true, true);
		if (mission && mission->missionInterface)
			mission->missionInterface->drawVTOL();
		if (!drawOldWay && !inMovieMode)
		{
			if (compass && (turn > 3) && drawCompass)
				compass->render(-1); // Force this to zBuffer in front of everything
		}
		if (!drawOldWay)
			mcTextureManager->renderLists(); // This sends triangles down to the
											 // card.  All "rendering" to this
											 // point has been setting up tri
											 // lists
		if (drawOldWay)
		{
			// Last thing drawn were shadows which are not Gouraud Shaded!!!
			// MLR to be "efficient" doesn't set this state by default at
			// startup!
			gos_SetRenderState(gos_State_ShadeMode, gos_ShadeGouraud);
		}
		theClipper->RenderNow(); // Draw the FX
		if (useNonWeaponEffects)
			weather->render(); // Draw the weather
	}
	if (drawOldWay && !inMovieMode)
	{
		gos_SetRenderState(gos_State_ZCompare, 0);
		gos_SetRenderState(gos_State_ZWrite, 0);
		gos_SetRenderState(gos_State_Perspective, 1);
		if (compass && (turn > 3) && drawCompass)
			compass->render();
	}
	//---------------------------------------------------------
	// Check if we are inMovieMode and should be letterboxed.
	// draw letterboxes here.
	if (inMovieMode && (letterBoxPos != 0.0f))
	{
		// Figure out the two faces we need to draw based on letterBox Pos and
		// Alpha
		float barTopX = screenResolution.y * letterBoxPos;
		float barBotX = screenResolution.y - barTopX;
		gos_SetRenderState(gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
		gos_SetRenderState(gos_State_ShadeMode, gos_ShadeGouraud);
		gos_SetRenderState(gos_State_MonoEnable, 0);
		gos_SetRenderState(gos_State_Perspective, 0);
		gos_SetRenderState(gos_State_Clipping, 1);
		gos_SetRenderState(gos_State_AlphaTest, 1);
		gos_SetRenderState(gos_State_Specular, 0);
		gos_SetRenderState(gos_State_Dither, 1);
		gos_SetRenderState(gos_State_TextureMapBlend, gos_BlendModulate);
		gos_SetRenderState(gos_State_Filter, gos_FilterNone);
		gos_SetRenderState(gos_State_TextureAddress, gos_TextureClamp);
		gos_SetRenderState(gos_State_ZCompare, 0);
		gos_SetRenderState(gos_State_ZWrite, 0);
		gos_SetRenderState(gos_State_Texture, 0);
		//------------------------------------
		gos_VERTEX gVertex[4];
		gVertex[0].x	= 0.0f;
		gVertex[0].y	= 0.0f;
		gVertex[0].z	= 0.00001f;
		gVertex[0].rhw  = 0.00001f;
		gVertex[0].u	= 0.0f;
		gVertex[0].v	= 0.0f;
		gVertex[0].argb = (letterBoxAlpha << 24);
		gVertex[0].frgb = 0xff000000;
		gVertex[1].x	= 0.0f;
		gVertex[1].y	= barTopX;
		gVertex[1].z	= 0.00001f;
		gVertex[1].rhw  = 0.00001f;
		gVertex[1].u	= 0.0f;
		gVertex[1].v	= 0.0f;
		gVertex[1].argb = (letterBoxAlpha << 24);
		gVertex[1].frgb = 0xff000000;
		gVertex[2].x	= screenResolution.x;
		gVertex[2].y	= barTopX;
		gVertex[2].z	= 0.00001f;
		gVertex[2].rhw  = 0.00001f;
		gVertex[2].u	= 0.0f;
		gVertex[2].v	= 0.0f;
		gVertex[2].argb = (letterBoxAlpha << 24);
		gVertex[2].frgb = 0xff000000;
		gVertex[3].x	= screenResolution.x;
		gVertex[3].y	= 0.0f;
		gVertex[3].z	= 0.00001f;
		gVertex[3].rhw  = 0.00001f;
		gVertex[3].u	= 0.0f;
		gVertex[3].v	= 0.0f;
		gVertex[3].argb = (letterBoxAlpha << 24);
		gVertex[3].frgb = 0xff000000;
		gos_DrawQuads(gVertex, 4);
		gVertex[0].x	= 0.0f;
		gVertex[0].y	= barBotX;
		gVertex[0].z	= 0.00001f;
		gVertex[0].rhw  = 0.00001f;
		gVertex[0].u	= 0.0f;
		gVertex[0].v	= 0.0f;
		gVertex[0].argb = (letterBoxAlpha << 24);
		gVertex[0].frgb = 0xff000000;
		gVertex[1].x	= screenResolution.x;
		gVertex[1].y	= barBotX;
		gVertex[1].z	= 0.00001f;
		gVertex[1].rhw  = 0.00001f;
		gVertex[1].u	= 0.0f;
		gVertex[1].v	= 0.0f;
		gVertex[1].argb = (letterBoxAlpha << 24);
		gVertex[1].frgb = 0xff000000;
		gVertex[2].x	= screenResolution.x;
		gVertex[2].y	= screenResolution.y;
		gVertex[2].z	= 0.00001f;
		gVertex[2].rhw  = 0.00001f;
		gVertex[2].u	= 0.0f;
		gVertex[2].v	= 0.0f;
		gVertex[2].argb = (letterBoxAlpha << 24);
		gVertex[2].frgb = 0xff000000;
		gVertex[3].x	= 0.0f;
		gVertex[3].y	= screenResolution.y;
		gVertex[3].z	= 0.00001f;
		gVertex[3].rhw  = 0.00001f;
		gVertex[3].u	= 0.0f;
		gVertex[3].v	= 0.0f;
		gVertex[3].argb = (letterBoxAlpha << 24);
		gVertex[3].frgb = 0xff000000;
		gos_DrawQuads(gVertex, 4);
	}
	if (inMovieMode && (fadeAlpha != 0x0))
	{
		// We are fading to something other then clear screen.
		gos_SetRenderState(gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
		gos_SetRenderState(gos_State_ShadeMode, gos_ShadeGouraud);
		gos_SetRenderState(gos_State_MonoEnable, 0);
		gos_SetRenderState(gos_State_Perspective, 0);
		gos_SetRenderState(gos_State_Clipping, 1);
		gos_SetRenderState(gos_State_AlphaTest, 1);
		gos_SetRenderState(gos_State_Specular, 0);
		gos_SetRenderState(gos_State_Dither, 1);
		gos_SetRenderState(gos_State_TextureMapBlend, gos_BlendModulate);
		gos_SetRenderState(gos_State_Filter, gos_FilterNone);
		gos_SetRenderState(gos_State_TextureAddress, gos_TextureClamp);
		gos_SetRenderState(gos_State_ZCompare, 0);
		gos_SetRenderState(gos_State_ZWrite, 0);
		gos_SetRenderState(gos_State_Texture, 0);
		//------------------------------------
		gos_VERTEX gVertex[4];
		gVertex[0].x	= 0.0f;
		gVertex[0].y	= 0.0f;
		gVertex[0].z	= 0.00001f;
		gVertex[0].rhw  = 0.00001f;
		gVertex[0].u	= 0.0f;
		gVertex[0].v	= 0.0f;
		gVertex[0].argb = (fadeAlpha << 24) + (fadeColor & 0x00ffffff);
		gVertex[0].frgb = 0xff000000;
		gVertex[1].x	= 0.0f;
		gVertex[1].y	= screenResolution.y;
		gVertex[1].z	= 0.00001f;
		gVertex[1].rhw  = 0.00001f;
		gVertex[1].u	= 0.0f;
		gVertex[1].v	= 0.0f;
		gVertex[1].argb = (fadeAlpha << 24) + (fadeColor & 0x00ffffff);
		gVertex[1].frgb = 0xff000000;
		gVertex[2].x	= screenResolution.x;
		gVertex[2].y	= screenResolution.y;
		gVertex[2].z	= 0.00001f;
		gVertex[2].rhw  = 0.00001f;
		gVertex[2].u	= 0.0f;
		gVertex[2].v	= 0.0f;
		gVertex[2].argb = (fadeAlpha << 24) + (fadeColor & 0x00ffffff);
		gVertex[2].frgb = 0xff000000;
		gVertex[3].x	= screenResolution.x;
		gVertex[3].y	= 0.0f;
		gVertex[3].z	= 0.00001f;
		gVertex[3].rhw  = 0.00001f;
		gVertex[3].u	= 0.0f;
		gVertex[3].v	= 0.0f;
		gVertex[3].argb = (fadeAlpha << 24) + (fadeColor & 0x00ffffff);
		gVertex[3].frgb = 0xff000000;
		gos_DrawQuads(gVertex, 4);
	}
	//-----------------------------------------------------
}
Ejemplo n.º 28
0
void PieMenu::draw()
{
	// save the current OpenGL drawing matrix so we can freely modify it
	gGL.pushMatrix();

	// save the widget's rectangle for later use
	LLRect r = getRect();

	// initialize pie scale factor for popup effect
	F32 factor = getScaleFactor();

#if PIE_DRAW_BOUNDING_BOX
	// draw a bounding box around the menu for debugging purposes
	gl_rect_2d(0, r.getHeight(), r.getWidth(), 0, LLColor4::white, FALSE);
#endif

	// set up pie menu colors
	LLColor4 lineColor = LLUIColorTable::instance().getColor("PieMenuLineColor");
	LLColor4 selectedColor = LLUIColorTable::instance().getColor("PieMenuSelectedColor");
	LLColor4 textColor = LLUIColorTable::instance().getColor("PieMenuTextColor");
	LLColor4 bgColor = LLUIColorTable::instance().getColor("PieMenuBgColor");
	LLColor4 borderColor = bgColor % 0.3f;

	// if the user wants their own colors, apply them here
	static LLCachedControl<bool> sOverridePieColors(gSavedSettings, "OverridePieColors", false);
	if (sOverridePieColors)
	{
		static LLCachedControl<F32> sPieMenuOpacity(gSavedSettings, "PieMenuOpacity");
		static LLCachedControl<F32> sPieMenuFade(gSavedSettings, "PieMenuFade");
		bgColor = LLUIColorTable::instance().getColor("PieMenuBgColorOverride") % sPieMenuOpacity;
		borderColor = bgColor % (1.f - sPieMenuFade);
		selectedColor = LLUIColorTable::instance().getColor("PieMenuSelectedColorOverride");
	}

	// on first click, make the menu fade out to indicate "borderless" operation
	if (mFirstClick)
	{
		borderColor %= 0.f;
	}

	// move origin point to the center of our rectangle
	gGL.translatef(r.getWidth() / 2, r.getHeight() / 2, 0);

	// draw the general pie background
	gl_washer_2d(PIE_OUTER_SIZE * factor, PIE_INNER_SIZE, 32, bgColor, borderColor);

	// set up an item list iterator to point at the beginning of the item list
	slice_list_t::iterator cur_item_iter;
	cur_item_iter = mSlices->begin();

	// clear current slice pointer
	mSlice = NULL;
	// current slice number is 0
	S32 num = 0;
	bool wasAutohide = false;
	do
	{
		// standard item text color
		LLColor4 itemColor = textColor;

		// clear the label and set up the starting angle to draw in
		std::string label("");
		F32 segmentStart = F_PI / 4.f * (F32)num - F_PI / 8.f;

		// iterate through the list of slices
		if (cur_item_iter != mSlices->end())
		{
			// get current slice item
			LLView* item = (*cur_item_iter);

			// check if this is a submenu or a normal click slice
			PieSlice* currentSlice = dynamic_cast<PieSlice*>(item);
			PieMenu* currentSubmenu = dynamic_cast<PieMenu*>(item);
			// advance internally to the next slice item
			cur_item_iter++;

			// in case it is regular click slice
			if (currentSlice)
			{
				// get the slice label and tell the slice to check if it's supposed to be visible
				label = currentSlice->getLabel();
				currentSlice->updateVisible();
				// disable it if it's not visible, pie slices never really disappear
				BOOL slice_visible = currentSlice->getVisible();
				currentSlice->setEnabled(slice_visible);
				if (!slice_visible)
				{
				//	LL_DEBUGS() << label << " is not visible" << LL_ENDL;
					label = "";
				}

				// if the current slice is the start of an autohide chain, clear out previous chains
				if (currentSlice->getStartAutohide())
				{
					wasAutohide = false;
				}

				// check if the current slice is part of an autohide chain
				if (currentSlice->getAutohide())
				{
					// if the previous item already won the autohide, skip this item
					if (wasAutohide)
					{
						continue;
					}

					// look at the next item in the pie
					LLView* lookAhead = (*cur_item_iter);
					// check if this is a normal click slice
					PieSlice* lookSlice = dynamic_cast<PieSlice*>(lookAhead);
					if (lookSlice)
					{
						// if the next item is part of the current autohide chain as well ...
						if (lookSlice->getAutohide() && !lookSlice->getStartAutohide())
						{
							// ... it's visible and it's enabled, skip the current one.
							// the first visible and enabled item in autohide chains wins
							// this is useful for Sit/Stand toggles
							lookSlice->updateEnabled();
							lookSlice->updateVisible();
							if (lookSlice->getVisible() && lookSlice->getEnabled())
							{
								continue;
							}

							// this item won the autohide contest
							wasAutohide = true;
						}
					}
				}
				else
				{
					// reset autohide chain
					wasAutohide = false;
				}

				// check if the slice is currently enabled
				currentSlice->updateEnabled();
				if (!currentSlice->getEnabled())
				{
					LL_DEBUGS() << label << " is disabled" << LL_ENDL;
					// fade the item color alpha to mark the item as disabled
					itemColor %= 0.3f;
				}
			}
			// if it's a submenu just get the label
			else if (currentSubmenu)
			{
				label = currentSubmenu->getLabel();
			}

			// if it's a slice or submenu, the mouse pointer is over the same segment as our counter and the item is enabled
			if ((currentSlice || currentSubmenu) && (mCurrentSegment == num) && item->getEnabled())
			{
				// memorize the currently highlighted slice for later
				mSlice = item;
				// if we highlighted a different slice than before, we must play a sound
				if (mOldSlice != mSlice)
				{
					// get the appropriate UI sound and play it
					char soundNum = '0' + num;
					std::string soundName = "UISndPieMenuSliceHighlight";
					soundName += soundNum;

					make_ui_sound(soundName.c_str());
					// remember which slice we highlighted last, so we only play the sound once
					mOldSlice = mSlice;
				}

				// draw the currently highlighted pie slice
				gl_washer_segment_2d(PIE_OUTER_SIZE * factor, PIE_INNER_SIZE, segmentStart + 0.02f, segmentStart + F_PI / 4.f - 0.02f, 4, selectedColor, borderColor);
			}
		}
		// draw the divider line for this slice
		gl_washer_segment_2d(PIE_OUTER_SIZE * factor, PIE_INNER_SIZE, segmentStart - 0.02f, segmentStart + 0.02f, 4, lineColor, borderColor);

		// draw the slice labels around the center
		mFont->renderUTF8(label,
							0,
							PIE_X[num],
							PIE_Y[num],
							itemColor,
							LLFontGL::HCENTER,
							LLFontGL::VCENTER,
							LLFontGL::NORMAL,
							LLFontGL::DROP_SHADOW_SOFT);
		// next slice
		num++;
	}
	while (num < 8);	// do this until the menu is full

	// draw inner and outer circle, outer only if it was not the first click
	if (!mFirstClick)
	{
		gl_washer_2d(PIE_OUTER_SIZE * factor, PIE_OUTER_SIZE * factor - 2.f, 32, lineColor, borderColor);
	}
	gl_washer_2d(PIE_INNER_SIZE + 1, PIE_INNER_SIZE - 1, 16, borderColor, lineColor);

	// restore OpenGL drawing matrix
	gGL.popMatrix();

	// give control back to the UI library
	LLView::draw();
}
Ejemplo n.º 29
0
/**
 * Handle pointer moves.
 * @param point The pointer position on the screen.
 */
void ScreenImageSwiper::handlePointerMoved(MAPoint2d point)
{
	float scaleFactor = getScaleFactor();
	// Update the end swipe position.
	mPointerXEnd = (int)((float) point.x * scaleFactor);
}
Ejemplo n.º 30
0
// === PUBLIC SLOTS ===
void ImageEditor::scaleUp(int val){
  qreal sf = getScaleFactor();
  sf+= ((qreal) val)/100.0;
  if(sf>2){ sf = 2.0; }
  rescaleImage(sf);
}