Ejemplo n.º 1
0
/*!
    \fn swDesktop::Resize( const Size& newSize )
 */
void swDesktop::Resize( const Size& newSize )
{
    swUiControl::Resize( newSize );
    _wr = StartWrite();
    _wr->Clear();
    _wr->Fill( Geometry(), swTAttr(4, 6, 0), ACS_CKBOARD);
    // ------------------------------------------------- TESTS

    RedrawScreen();
    
}
 double operator()(const double x, const double y) const noexcept
 {
   const auto co_double = m_f(x,y);
   const Plane::Coordinat3D co_apfloat(
     apfloat(boost::geometry::get<0>(co_double)),
     apfloat(boost::geometry::get<1>(co_double)),
     apfloat(boost::geometry::get<2>(co_double))
   );
   const auto error_apfloat = m_plane.CalcError(co_apfloat);
   return Geometry().ToDoubleSafe(error_apfloat);
   //return m_plane.CalcError(m_f(x,y));
 }
void ribi::bnkn::SpriteNonMoving::Collision(
  const SpriteNonMoving& obstacle, SpriteMoving& moving
)
{
  if (!IsCollision(obstacle,moving)) return;
  /*

    O     -
          |
          | dy (in this case > 0)
          |
        M -
    |---|
      dx (in this case > 0)
  */
  const double dx = moving.getX() - obstacle.getX();
  const double dy = moving.getY() - obstacle.getY();
  //const double collision_distance
  //  = boost::numeric_cast<double>(obstacle.m_size + moving.m_size) / 2.0;
  //Obtain the relative angle between the players

  /*

    O
     \
      \
       \
        M

  angle_players in this case 135 degrees

  */
  const double angle_players = Geometry().GetAngleClockScreen(dx,dy);

  //Obtain the moving sprite's current impulse
  double moving_angle = moving.CalcImpulseAngle();
  double moving_speed = moving.CalcImpulseSpeed();
  //Obstacles have opposite impulse
  const double pi = boost::math::constants::pi<double>();
  double obstacle_angle = moving_angle + pi;
  double obstancle_speed = moving_speed;
  //Obtain the new impulses
  DoPerfectElasticCollision(
    angle_players, obstacle_angle,obstancle_speed,moving_angle,moving_speed
  );
  //Set the player's new impulse
  const double dx2 =  std::sin(moving_angle) * moving_speed;
  const double dy2 = -std::cos(moving_angle) * moving_speed;
  moving.SetSpeed(dx2,dy2);
  //Let the player move again
  moving.Move();
}
Ejemplo n.º 4
0
Polygon Polygon::transform(const SpatialReference& ref) const
{
    if (m_srs.empty())
        throw pdal_error("Polygon::transform failed due to m_srs being empty");
    if (ref.empty())
        throw pdal_error("Polygon::transform failed due to ref being empty");

    gdal::SpatialRef fromRef(m_srs.getWKT());
    gdal::SpatialRef toRef(ref.getWKT());
    gdal::Geometry geom(wkt(12, true), fromRef);
    geom.transform(toRef);
    return Geometry(geom.wkt(), ref);
}
Ejemplo n.º 5
0
void
Triangle_Processor::Divide(unsigned int N, Stack<AtomicRegion>&  Offspring)
  {
  Stack<Triangle> Parts;  
  Vector<unsigned int> DiffOrder(Diffs.Size());
  real NewVolume;
  
  switch(N)
    {
    case 2: 
    {    
    NewVolume = Geometry().Volume()/2;

    TheRule->ComputeDiffs(LocalIntegrand(),Geometry(),Diffs);

    // Sort the differences in descending order.
    for (unsigned int ik=0 ; ik<=2 ; ik++)  { DiffOrder[ik] = ik; }
    for (unsigned int i=0 ; i<=1 ; i++)  
      {
      for (unsigned int k=i+1 ; k<=2 ; k++)
         if (Diffs[DiffOrder[k]]>Diffs[DiffOrder[i]])
            {
            unsigned int h = DiffOrder[i];
            DiffOrder[i] = DiffOrder[k];
            DiffOrder[k] = h;
            }
      }
    TheDivisor2->Apply (Geometry(),Parts,DiffOrder);
    break;
    }
  
    case 4:
    {
    NewVolume = Geometry().Volume()/4;
    TheDivisor4->Apply (Geometry(),Parts,DiffOrder);
    break;
    }
  
    default:
      {
        NewVolume = Geometry().Volume()/N; 
        Error(True,"This kind of subdivision is not implemented");
      }
    }
  
  
  for (unsigned int i =0;i<N;i++)
    {
    Triangle* g = Parts.Pop();
    g->Volume(NewVolume);
    Processor<Triangle>* p = Descendant();
    Atomic<Triangle>* a = new Atomic<Triangle>(g,p);
    a->LocalIntegrand(&LocalIntegrand());
    Offspring.Push(a);
    };
    
  return;

  }
bool ribi::trim::CellsCreator::IsPlane(const std::vector<boost::shared_ptr<Point>>& v) noexcept
{
  std::vector<Point::Coordinat3D> w;
  std::transform(v.begin(),v.end(),std::back_inserter(w),
    [](const boost::shared_ptr<Point>& p)
    {
      assert(p);

      return p->GetCoordinat3D();
    }
  );
  assert(v.size() == w.size());
  return Geometry().IsPlane(w);
}
Ejemplo n.º 7
0
/**
 * @brief Axis::Axis
 *tworzy oś z paramterami:
 *czcionka: Verdana, 8pt
 *wartość minimalna: 0
 *wartość maksymalna: 100
 *odstęp wartości: 10
 *podziałka: 4px skierowana do wewnątrz
 *pusta etykieta
 *bez jednostki
 *domyślny styl linii
 */
Axis::Axis()
{
    //this->autoscale = false;
    this->font = QFont("verdana", 8);
    this->geometry = Geometry();
    this->max = 100;
    this->min = 0;
    this->tick = 10;
    this->tickDirection = inside;
    this->tickSize = 4;
    this->position = left;
    this->showUnit = false;
    this->label = Label();
    this->unit = "";
    this->lineStyle = LineStyle();
}
Ejemplo n.º 8
0
std::vector<double> ribi::PlaneZ::CalcPlaneZ(
  const Coordinat3D& p1,
  const Coordinat3D& p2,
  const Coordinat3D& p3
) noexcept
{
  
  const auto v(
    Geometry().CalcPlane(
      p1,
      p2,
      p3
    )
  );
  assert(v.size() == 4);
  return v;
}
bool ribi::Geometry::IsCounterClockwiseCartesian(
  const Coordinats3D& points,
  const Coordinat3D& observer
) const noexcept
{
  // const bool verbose{false};
  const int n_points{static_cast<int>(points.size())};
  assert(n_points == 3 || n_points == 4);
  if (n_points == 3)
  {
    const auto a = points[0];
    const auto b = points[1];
    const auto c = points[2];
    const auto normal = CalcNormal(a,b,c);
    const double direction{CalcDotProduct(normal,a - observer)};
    const bool is_counter_clockwise{direction > 0.0}; //Difference between CW ('<') and CCW ('>')
    return is_counter_clockwise;
  }
  else
  {
    assert(n_points == 4);
    //See if the points in the projection are in the same direction
    assert(Geometry().IsPlane(points));
    const std::unique_ptr<Plane> plane(new Plane(points[0],points[1],points[2]));
    assert(plane);
    const auto v =
      plane->CalcProjection(
        {
          points[0],
          points[1],
          points[2],
          points[3]
        }
      )
    ;

    //If the points are messed up, they cannot be clockwise
    if (!IsClockwiseCartesianHorizontal(v) && !IsCounterClockwiseCartesianHorizontal(v)) return false;
    //The neatly orderder point have the same winding as the first three
    std::remove_const<std::remove_reference<decltype(points)>::type>::type a;
    std::copy(points.begin() + 0,points.begin() + 3,std::back_inserter(a));
    return IsCounterClockwiseCartesian(a,observer);
  }

}
Ejemplo n.º 10
0
void tIMX51Video::UpdateVideoGeometry()
{
    QRect originalRect = Geometry();
    QRect rect = originalRect;
    QSize s = SensorSize();

    double sensorRatio = (double)s.width() / (double)s.height();
    double outputRatio = (double)rect.width() / (double)rect.height();

    if( sensorRatio >= outputRatio )
    {
        rect.setHeight(rect.height() * outputRatio / sensorRatio);
    }
    else
    {
        rect.setWidth(rect.width() * sensorRatio / outputRatio);
    }

    // MX51 IPU restricted to output sizes of 8x8 pixel multiples
    // Also there also seems to be occasional problems with sizes > 760 pixels high
    rect.setWidth(rect.width() - rect.width() % 8);
    if(rect.height() > 760)
        rect.setHeight(760);
    else
        rect.setHeight(rect.height() - rect.height() % 8);

    if(originalRect.width() > rect.width())
        rect.moveLeft(rect.left() + (originalRect.width() - rect.width()) / 2);
    if(originalRect.height() > rect.height())
        rect.moveTop(rect.top() + (originalRect.height() - rect.height()) / 2);

    /*qDebug() << "sensorSize = " << s;
    qDebug() << "originalRect = " << originalRect;
    qDebug() << "videoGeometry = " << rect;*/
   
    if (originalRect.height() == 480)
        rect.setHeight(480);

    m_VideoGeometry = rect;

    emit Sr2VideoGeometryChanged();
}
Ejemplo n.º 11
0
Geometry GeometryApi::GetGeometryFromParams( int paramIndex,
                                             bool& found,
                                             v8::Isolate* isolate,
                                             const v8::FunctionCallbackInfo< v8::Value >& args )
{
  found = false;

  v8::HandleScope handleScope( isolate );
  BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::GEOMETRY, isolate, args );
  if( wrappedObject )
  {
    found = true;
    GeometryWrapper* wrapper = static_cast< GeometryWrapper *>(wrappedObject);
    return wrapper->GetGeometry();
  }
  else
  {
    return Geometry();
  }
}
Ejemplo n.º 12
0
AdaptiveLayout::tKey AdaptiveLayout::tKey::Interpolate(const tKey& keyA, const tKey& keyB, const tKey& keyC,
    float ta, float tb, float tc)
{
    tKey res;
    res.m_Position = QPoint(
        int(float(keyA.m_Position.x()) * ta + float(keyB.m_Position.x()) * tb + float(keyC.m_Position.x()) * tc),
        int(float(keyA.m_Position.y()) * ta + float(keyB.m_Position.y()) * tb + float(keyC.m_Position.y()) * tc)
        );
    if( keyA.m_Actors.size() != keyB.m_Actors.size() || keyA.m_Actors.size() != keyC.m_Actors.size() )
    {
        return res;
    }
    res.m_Properties = keyA.m_Properties;
    res.m_Actors.reserve(keyA.m_Actors.size());
    for( int iactor = 0; iactor < keyA.m_Actors.size(); iactor++ )
    {
        const tActor& actorA = keyA.m_Actors[iactor];
        const tActor& actorB = keyB.m_Actors[iactor];
        const tActor& actorC = keyC.m_Actors[iactor];
        const Geometry &ga = actorA.geo;
        const Geometry &gb = actorB.geo;
        const Geometry &gc = actorC.geo;
        tActor actor;
        actor.geo = Geometry(
            ga.cx * ta + gb.cx * tb + gc.cx * tc,
            ga.cy * ta + gb.cy * tb + gc.cy * tc,
            ga.hw * ta + gb.hw * tb + gc.hw * tc,
            ga.hh * ta + gb.hh * tb + gc.hh * tc
            );
        actor.props.resize(qMin(actorA.props.size(), qMin(actorB.props.size(), actorC.props.size())));
        for( int i = 0; i < actor.props.size(); i++ )
        {
            actor.props[i] = actorA.props[i] * ta + actorB.props[i] * tb + actorC.props[i] * tc;
        }
        res.m_Actors.push_back(actor);
    }
    return res;
}
ribi::trim::Winding ribi::trim::CalcWindingHorizontal(const std::vector<boost::shared_ptr<const Edge>>& edges)
{
  //Are Edges nicely ordered
  // 0: A->B (edge[0] has A at its m_points[0] and has B at its m_points[1])
  // 1: B->C (edge[1] has B at its m_points[0] and has C at its m_points[1])
  // 2: C->A (edge[2] has C at its m_points[0] and has A at its m_points[1])
  const int n_edges { static_cast<int>(edges.size()) };

  //Check for indeterminate ordering
  for (int i=0; i!=n_edges; ++i)
  {
    const int j { (i + 1) % n_edges };
    assert(i < static_cast<int>(edges.size()));
    assert(j < static_cast<int>(edges.size()));
    if (edges[i]->GetTo() != edges[j]->GetFrom())
    {
      return Winding::indeterminate;
    }
  }
  //Extract the points
  std::vector<Coordinat3D> points;
  for (int i=0; i!=n_edges; ++i)
  {
    Coordinat3D co(
      edges[i]->GetFrom()->GetCoordinat()->GetX(),
      edges[i]->GetFrom()->GetCoordinat()->GetY(),
      edges[i]->GetFrom()->GetZ().value()
    );
    points.push_back(co);
  }
  assert(points.size() == edges.size());

  HUH, ER IS OOK EEN NORMALE sClockwiseHorizontal(points, MET ABOVE HIERO)
  return Geometry().IsClockwiseHorizontal(points)
    ? Winding::clockwise
    : Winding::counter_clockwise
  ;
}
bool ribi::trim::IsClockwiseHorizontal(const std::vector<boost::shared_ptr<Point>>& points) noexcept
{
  assert(points.size() == 3);
  double center_x = 0.0;
  double center_y = 0.0;
  for (const auto point: points)
  {
    center_x += point->GetCoordinat()->GetX();
    center_y += point->GetCoordinat()->GetY();
  }
  center_x /= static_cast<double>(points.size());
  center_y /= static_cast<double>(points.size());

  //const double pi  = boost::math::constants::pi<double>();
  //const double tau = boost::math::constants::two_pi<double>();
  const bool a {
    Geometry().IsClockwise(
      Geometry().GetAngle(
        points[0]->GetCoordinat()->GetX() - center_x,
        points[0]->GetCoordinat()->GetY() - center_y
      ),
      Geometry().GetAngle(
        points[1]->GetCoordinat()->GetX() - center_x,
        points[1]->GetCoordinat()->GetY() - center_y
      )
    )
  };
  const bool b {
    Geometry().IsClockwise(
      Geometry().GetAngle(
        points[1]->GetCoordinat()->GetX() - center_x,
        points[1]->GetCoordinat()->GetY() - center_y
      ),
      Geometry().GetAngle(
        points[2]->GetCoordinat()->GetX() - center_x,
        points[2]->GetCoordinat()->GetY() - center_y
      )
    )
  };
  //TRACE(a);
  //TRACE(b);
  const bool is_clockwise { a && b };
  //TRACE(is_clockwise);
  return is_clockwise;
}
Ejemplo n.º 15
0
Image thin_image(const Image &box, double THRESHOLD_BOND, const ColorGray &bgColor)
{
  Image image(Geometry(box.columns(), box.rows()), "white");
  image.type(GrayscaleType);
  unsigned int xsize = box.columns();
  unsigned int ysize = box.rows();
  unsigned char *ptr = (unsigned char*) malloc(xsize * ysize * sizeof(unsigned char));

  for (unsigned int i = 0; i < xsize; i++)
    for (unsigned int j = 0; j < ysize; j++)
      ptr[i + j * xsize] = get_pixel(box, bgColor, i, j, THRESHOLD_BOND);

  if (xsize>1 && ysize>1)
    thin1(ptr, xsize, ysize);

  for (unsigned int i = 0; i < xsize; i++)
    for (unsigned int j = 0; j < ysize; j++)
      if (ptr[i + j * xsize] == 1)
        image.pixelColor(i, j, "black");

  free(ptr);
  return (image);
}
Ejemplo n.º 16
0
bool CMagicKHelper::ResizeImage( const tstring strSrcImg,const tstring strDestImg, unsigned int width, unsigned int height )
{
	CLogger::GetInstance()->PrintErrLog("begin resize image srcimg = %s, strDestImg = %s", strSrcImg.c_str(), strDestImg.c_str());
	Magick::Image imgSrc;//(strSrcImg);
	try { 

//			EnterCriticalSection(cs_);
			imgSrc.read(strSrcImg);	
			CLogger::GetInstance()->PrintErrLog("read successed");
			imgSrc.sample(Geometry(width,height));  
			CLogger::GetInstance()->PrintErrLog("sample successed");
			imgSrc.write(strDestImg);
//			LeaveCriticalSection(cs_);
			CLogger::GetInstance()->PrintErrLog("write successed");
	} 
	catch(std::exception &ex) 
	{ 
		//文件读取失败
		CLogger::GetInstance()->PrintErrLog("resize image failure  %s", ex.what());
		return false;
	} 
	return true;
}
Ejemplo n.º 17
0
	bool Descriptor::build( string _filename, 
							float _width, float _height, 
							float _offX,  float _offY)
	{
		try
		{
			Image image; image.read(_filename);

			if (_width != 1.0 || _height != 1.0)
			{
				int iWidth  = int(_width*image.columns());
				int iHeight = int(_height*image.rows());
				int iOffX   = int(_offX*image.columns());
				int iOffY 	= int(_offY*image.rows());

				image.crop( Geometry( iWidth, iHeight, iOffX, iOffY ));
			}

			filename_ = _filename;
			build(image);
		}
		catch (Exception e) { return false; }
		return true;
	}
ribi::About ribi::TestConceptMapMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "TestConceptMap",
    "tests the ConceptMap classes",
    "on April 9th 2016",
    "2013-2016",
    "http://www.richelbilderbeek.nl/ToolTestConceptMap.htm",
    GetVersion(),
    GetVersionHistory());

  a.AddLibrary("apfloat version: 2.4.1");
  //a.AddLibrary("ConceptMap version: " + ribi::cmap::ConceptMap::GetVersion());
  a.AddLibrary("Container version: " + ribi::Container().GetVersion());
  a.AddLibrary("FileIo version: " + FileIo().GetVersion());
  a.AddLibrary("Geometry version: " + Geometry().GetVersion());
  a.AddLibrary("ribi::Regex version: " + Regex().GetVersion());
  a.AddLibrary("Plane version: " + Plane::GetVersion());
  a.AddLibrary("TestTimer version: " + TestTimer::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());

  return a;
}
Ejemplo n.º 19
0
void MainWindow::on_pushButton_clicked()
{
    Axis x;
    x.setFont(QFont("arial", 8));
    x.setTick(ui->eTick->text().toDouble());
    if(ui->cKierunek->currentText()=="wewnątrz")
        x.setTickDirection(inside);
    else if(ui->cKierunek->currentText()=="zewnątrz")
        x.setTickDirection(outside);
    else x.setTickDirection(middle);
    x.setTickSize(4);
    x.setMax(ui->eMax->text().toDouble());
    x.setMin(ui->eMin->text().toDouble());
    x.setPosition(left);
    x.setUnitVisibility(ui->cJednostka->isChecked());
    x.setGeometry(Geometry(0, 0, 40, 400));
    x.setUnit(ui->eJednostka->text());
    x.draw();

    ch.removeAxisY(0);
    ch.addAxisY(x);
    ch.drawBackground();
    ui->label->setPixmap(ch.draw());
}
Ejemplo n.º 20
0
//WARNING: This code makes a big assumption -- that your models have texture coordinates AND normals which they should have anyway (else you can't do texturing and lighting!)
//If your .obj file has no lines beginning with "vt" or "vn", then you'll need to change the Export settings in your modelling software so that it exports the texture coordinates 
//and normals. If you still have no "vt" lines, you'll need to do some texture unwrapping, also known as UV unwrapping.
Geometry OBJLoader::Load(char* filename, ID3D11Device* _pd3dDevice, bool invertTexCoords)
{
	std::string binaryFilename = filename;
	binaryFilename.append("Binary");
	std::ifstream binaryInFile;
	binaryInFile.open(binaryFilename, std::ios::in | std::ios::binary);

	if (!binaryInFile.good())
	{
		std::ifstream inFile;
		inFile.open(filename);

		if (!inFile.good())
		{
			return Geometry();
		}
		else
		{
			//Vectors to store the vertex positions, normals and texture coordinates. Need to use vectors since they're resizeable and we have
			//no way of knowing ahead of time how large these meshes will be
			std::vector<XMFLOAT3> verts;
			std::vector<XMFLOAT3> normals;
			std::vector<XMFLOAT2> texCoords;

			//DirectX uses 1 index buffer, OBJ is optimized for storage and not rendering and so uses 3 smaller index buffers.....great...
			//We'll have to merge this into 1 index buffer which we'll do after loading in all of the required data.
			std::vector<unsigned short> vertIndices;
			std::vector<unsigned short> normalIndices;
			std::vector<unsigned short> textureIndices;

			std::string input;

			XMFLOAT3 vert;
			XMFLOAT2 texCoord;
			XMFLOAT3 normal;
			unsigned short vInd[3]; //indices for the vertex position
			unsigned short tInd[3]; //indices for the texture coordinate
			unsigned short nInd[3]; //indices for the normal
			std::string beforeFirstSlash;
			std::string afterFirstSlash;
			std::string afterSecondSlash;

			while (!inFile.eof()) //While we have yet to reach the end of the file...
			{
				inFile >> input; //Get the next input from the file

								 //Check what type of input it was, we are only interested in vertex positions, texture coordinates, normals and indices, nothing else
				if (input.compare("v") == 0) //Vertex position
				{
					inFile >> vert.x;
					inFile >> vert.y;
					inFile >> vert.z;

					verts.push_back(vert);
				}
				else if (input.compare("vt") == 0) //Texture coordinate
				{
					inFile >> texCoord.x;
					inFile >> texCoord.y;

					if (invertTexCoords) texCoord.y = 1.0f - texCoord.y;

					texCoords.push_back(texCoord);
				}
void ribi::Chess::GameWidget::Test() noexcept
{
  //Testing Chess::Piece exactly once
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  const ribi::TestTimer test_timer(__func__,__FILE__,1.0);
  #ifdef FIX_ISSUE_240
  {
    {
      const boost::shared_ptr<Chess::Game> game
        = boost::make_shared<Chess::Game>();
      const boost::shared_ptr<Chess::ChessWidget> w(
        new GameWidget(game,Geometry().CreateRect(0,0,100,100)));
      w->ClickPixel(-1,-1);
      w->ClickPixel(1000,1000);
    }
    {
      const boost::shared_ptr<Chess::Game> game
        = boost::make_shared<Chess::Game>();
      const boost::shared_ptr<Chess::GameWidget> widget(
        new Chess::GameWidget(game,Geometry().CreateRect(0,0,100,100)));
      assert(widget->GetSelector()->GetCursor()->GetFile() == Chess::File("a"));
      assert(widget->GetSelector()->GetCursor()->GetRank() == Chess::Rank("1"));
      assert(!widget->GetSelector()->GetSelected());
      //Check clicking: cursor will always follow
      for (int x=0;x!=8;++x)
      {
        for (int y=0;y!=8;++y)
        {
          const boost::shared_ptr<Square> square {
            SquareFactory().Create(
              File(x),Rank(y)
            )
          };
          widget->Click(square);
          assert(*widget->GetSelector()->GetCursor() == *square);
        }
      }
      //Check selection: Board::Widget will select any Chess::Piece, Board::Game only those of the active player
      //Click on own piece, selecting it
      {
        const boost::shared_ptr<Square> square {
          SquareFactory().Create("b1")
        };
        widget->Click(square);
      }
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("b1"));
      assert(widget->GetSelector()->GetSelected());
      assert(*widget->GetSelector()->GetSelected() == *SquareFactory().Create("b1"));

      //Click on empty square, selected piece remains
      widget->Click(SquareFactory().Create("d4"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("d4"));
      assert(widget->GetSelector()->GetSelected());
      assert(*widget->GetSelector()->GetSelected() == *SquareFactory().Create("b1"));

      //Click on selected square, undoing selection
      widget->Click(SquareFactory().Create("b1"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("b1"));
      assert(!widget->GetSelector()->GetSelected());

      //Click on enemy square, Chess::Board will select it
      widget->Click(SquareFactory().Create("h8"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("g8"));
      assert(!widget->GetSelector()->GetSelected());

      //Playing e7-e5 must succeed for a Board, must fail for a Game
      assert( game->GetBoard()->GetPiece(SquareFactory().Create("e7")));
      assert(!game->GetBoard()->GetPiece(SquareFactory().Create("e5")));
      widget->Click(SquareFactory().Create("e7"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("e7"));
      assert(!widget->GetSelector()->GetSelected());

      widget->Click(SquareFactory().Create("e5"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("e5"));
      assert(!widget->GetSelector()->GetSelected());
      assert( game->GetBoard()->GetPiece(SquareFactory().Create("e7")));
      assert(!game->GetBoard()->GetPiece(SquareFactory().Create("e5")));

      //Playing e2-e4 must succeed for both Board and Game
      assert( game->GetBoard()->GetPiece(SquareFactory().Create("e2")));
      assert(!game->GetBoard()->GetPiece(SquareFactory().Create("e4")));
      widget->Click(SquareFactory().Create("e2"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("e2"));
      assert(widget->GetSelector()->GetSelected());
      assert(*widget->GetSelector()->GetSelected() == *SquareFactory().Create("e2"));

      widget->Click(SquareFactory().Create("e4"));
      assert(*widget->GetSelector()->GetCursor() == *SquareFactory().Create("e4"));
      assert(!widget->GetSelector()->GetSelected());
      assert(!game->GetBoard()->GetPiece(SquareFactory().Create("e2")));
      assert( game->GetBoard()->GetPiece(SquareFactory().Create("e4")));
    }
  }
  #endif
}
Ejemplo n.º 22
0
Geometry Geometry::fixedHorizontalScalableVertical(int x, unsigned width, int yPercent, unsigned heightPercent, unsigned originalScreenHeight)
	{
	int y = originalScreenHeight * yPercent / 100;
	unsigned height = originalScreenHeight * heightPercent / 100;
	return Geometry(SizePolicy::Fixed, SizePolicy::Scalable, x, y, width, height, 0, originalScreenHeight);
	}
Ejemplo n.º 23
0
Geometry Geometry::fixed(const Point& position, const Size& size)
	{
	return Geometry(SizePolicy::Fixed, SizePolicy::Fixed, position.x(), position.y(), size.width(), size.height(), 0, 0);
	}
Ejemplo n.º 24
0
Geometry Window::geometry() {
  return Geometry(window->x(), window->y(), window->container->width(), window->container->height());
}
Ejemplo n.º 25
0
void
Triangle_Processor::Process( Stack<AtomicRegion>&  Offspring)
  {
  TimesCalled ++;
  if (TimesCalled == 1)
    {
    TheRule->Apply(LocalIntegrand(),Geometry(),Integral(),AbsoluteError());
    Offspring.MakeEmpty();
    return;
    };
  if(TimesCalled == 2)
    {
    real NewVolume
          = Geometry().Volume()/2;
    Stack<Triangle> Parts;
    Vector<unsigned int> DiffOrder(Diffs.Size());
    const real difffac = real(1)/real(0.45);    
    const real difftreshold = 1e-3;

    TheRule->ComputeDiffs(LocalIntegrand(),Geometry(),Diffs); 

    // Sort the differences in descending order.
    for (unsigned int ik=0 ; ik<=2 ; ik++)  { DiffOrder[ik] = ik; }
    for (unsigned int i=0 ; i<=1 ; i++)  
      {
     for (unsigned int k=i+1 ; k<=2 ; k++)
         if (Diffs[DiffOrder[k]]>Diffs[DiffOrder[i]])
            {
            unsigned int h = DiffOrder[i];
            DiffOrder[i] = DiffOrder[k];
            DiffOrder[k] = h;
            }
      }

    if (Diffs[DiffOrder[0]] < difftreshold)
      {
      TheDivisor4->Apply(Geometry(),Parts,DiffOrder);
      NewVolume /=2;
      }
    else 
      {
      if (Diffs[DiffOrder[0]]>difffac*Diffs[DiffOrder[2]])
        {
        TheDivisor2->Apply (Geometry(),Parts,DiffOrder);
        }
      else 
        { 
        TheDivisor4->Apply(Geometry(),Parts,DiffOrder);
        NewVolume /=2;
        }	
      };

    unsigned int N = Parts.Size();
    for (unsigned int ii =0;ii<N;ii++)
      {
      Triangle* g = Parts.Pop();
      g->Volume(NewVolume);
      Processor<Triangle>* p = Descendant();
      Atomic<Triangle>* a = new Atomic<Triangle>(g,p);
      a->LocalIntegrand(&LocalIntegrand());
      Offspring.Push(a);
      };
    return;
    };
   Error(TimesCalled > 2,
     "Triangle_Processor : more than two calls of Process()");
   }
Ejemplo n.º 26
0
Geometry Geometry::scalableHorizontalFixedVertical(int xPercent, unsigned widthPercent, unsigned originalScreenWidth, int y, unsigned height)
	{
	int x = originalScreenWidth * xPercent / 100;
	unsigned width = originalScreenWidth * widthPercent / 100;
	return Geometry(SizePolicy::Scalable, SizePolicy::Fixed, x, y, width, height, originalScreenWidth, 0);
	}
Ejemplo n.º 27
0
RETCODE __declspec(dllexport) xp_AsText(SRV_PROC *pSrvProc)
{
#ifdef _DEBUG
// In a debug build, look up the data type name for assistance.
DBCHAR *pdbcDataType = NULL;
int cbDataType = 0;
#endif

	COM_TRY {
	// Count up the number of input parameters.  There should be exactly two.
		if (2 != srv_rpcparams(pSrvProc)) 
			return PRINTUSAGE (pSrvProc);	// Send error message and return

	// Use srv_paraminfo to get data type and length information.
	BYTE bType1, bType2;
	ULONG cbMaxLen1, cbMaxLen2;
	ULONG cbActualLen1, cbActualLen2;
	BOOL fNull1, fNull2;

	// check 1st parameter
		if (FAIL == srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, NULL, &fNull1))
			return PRINTERROR(pSrvProc, "srv_paraminfo for parameter 1 failed...");

#ifdef _DEBUG
    // A debugging aid. Get the name of the data type of the parameter.
	    pdbcDataType = srv_symbol(SRV_DATATYPE, (int)bType1, &cbDataType);
#endif

	// make sure first parameter is of image datatype (should be geometry)
		if (bType1 != SRVIMAGE)
			return PRINTUSAGE(pSrvProc);

	// check 2nd parameter
		if (FAIL == srv_paraminfo(pSrvProc, 2, &bType2, &cbMaxLen2, &cbActualLen2, NULL, &fNull2))
			return PRINTERROR(pSrvProc, "srv_paraminfo for parameter 2 failed...");

#ifdef _DEBUG
    // A debugging aid. Get the name of the data type of the parameter.
	    pdbcDataType = srv_symbol(SRV_DATATYPE, (int)bType2, &cbDataType);
#endif

	// make sure second parameter is of ntext datatype
		if (bType2 != SRVNVARCHAR && bType2 != SRVBIGVARCHAR)
			return PRINTUSAGE(pSrvProc);

	// make sure second parameter is a return (OUTPUT) parameter
		if (!(srv_paramstatus(pSrvProc, 2) & SRV_PARAMRETURN))
			return PRINTUSAGE(pSrvProc);

	// retrieve geometry
	std::auto_ptr<BYTE> Geometry (new BYTE[cbActualLen1]);

		if (FAIL == srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, Geometry.get(), &fNull1))
			return PRINTERROR(pSrvProc, "srv_paraminfo(data) for parameter 1 failed...");
	
	// convert geometry to wkt format
	CComBSTR bstrWKT;
	WUnknown Unk (*(GUID *)Geometry.get());
	WPersistMemoryWks PM (Unk);

		THROW_FAILED_HRESULT(PM -> Load (Geometry.get() + sizeof(GUID), cbActualLen1 - sizeof(GUID)));
		THROW_FAILED_HRESULT(PM -> SaveWkt (&bstrWKT, false));

	// set output parameter
	ULONG ulLen = 0;
	BYTE *pOutData = NULL;

		USES_CONVERSION;
		if (SRVNVARCHAR == bType2) {
			pOutData = (BYTE *)bstrWKT.m_str;
			ulLen = min(cbMaxLen2, ULONG(bstrWKT.Length()*sizeof(OLECHAR)));
		} else {
			pOutData = (BYTE *)OLE2A(bstrWKT);
			ulLen = min(cbMaxLen2, ULONG(bstrWKT.Length()));
		}

		if (FAIL == srv_paramsetoutput(pSrvProc, 2, pOutData, ulLen, FALSE))
			return PRINTERROR(pSrvProc, "srv_paramsetoutput for parameter 2 failed...");

		srv_senddone(pSrvProc, SRV_DONE_MORE, 0, 0);

	} COM_CATCH_RETURN(XP_ERROR);
	return XP_NOERROR;
}
ribi::About ribi::ProjectRichelBilderbeekMenuDialog::GetAboutStatic() noexcept
{
  About a(
    "Richel Bilderbeek",
    "Project Richel Bilderbeek",
    "Richel Bilderbeek's work",
    "the 24th of May 2015",
    "2010-2015",
    "http://www.richelbilderbeek.nl/ProjectRichelBilderbeek.htm",
    GetVersionStatic(),
    GetVersionHistoryStatic());
  //a.AddLibrary("TestTwoDigitNewick version: " + WtTestTwoDigitNewickDialog::GetVersion());
  a.AddLibrary("AlphaBetaFilter version: " + AlphaBetaFilter::GetVersion());
  a.AddLibrary("AlphaBetaGammaFilter version: " + AlphaBetaGammaFilter::GetVersion());
  a.AddLibrary("AlphaFilter version: " + AlphaFilter::GetVersion());
  a.AddLibrary("Approximator version: " + Approximator<double,double>::GetVersion());
  a.AddLibrary("apfloat version: 2.4.1");
  a.AddLibrary("AsciiArter version: " + AsciiArterMenuDialog().GetVersion());

  a.AddLibrary("BeastR version: " + ribi::Beast().GetVersion());

  a.AddLibrary("BeerWanter version: " + BeerWanterMenuDialog().GetVersion());
  a.AddLibrary("Big Integer Library (by Matt McCutchen) version: 2010.04.30");
  a.AddLibrary("BinaryNewickVector version: " + BinaryNewickVector::GetVersion());
  a.AddLibrary("Boenken version: " + Boenken::MenuDialog().GetVersion());

#ifdef INCLUDE_BRAINWEAVER_20140617
  a.AddLibrary("Brainweaver version: " + pvdb::MenuDialog().GetVersion());
#endif // INCLUDE_BRAINWEAVER_20140617

  a.AddLibrary("Canvas version: " + Canvas::GetVersion());
#ifdef INCLUDE_CHESS_20140617
  a.AddLibrary("Chess::BitBoard version: " + Chess::BitBoard::GetVersion());
  a.AddLibrary("Chess::Board version: " + Chess::Board::GetVersion());
  a.AddLibrary("Chess::BoardWidget version: " + Chess::BoardWidget::GetVersion());
  a.AddLibrary("Chess::Game version: " + Chess::Game::GetVersion());
  a.AddLibrary("Chess::Widget version: " + Chess::ChessWidget::GetVersion());
#endif
#ifdef INCLUDE_CONCEPTMAP_20140811
  a.AddLibrary("cmap::ConceptMap version: " + cmap::ConceptMap::GetVersion());
  a.AddLibrary("cmap::ConceptMapWidget version: " + cmap::Widget::GetVersion());
#endif // INCLUDE_CONCEPTMAP_20140811
  a.AddLibrary("CodeToHtml version: " + c2h::CodeToHtmlMenuDialog().GetVersion());
  a.AddLibrary("ConnectThree version: " + con3::ConnectThree::GetVersion());
  a.AddLibrary("ConnectThreeWidget version: " + con3::ConnectThreeWidget::GetVersion());
  a.AddLibrary("Container version: " + Container().GetVersion());
  a.AddLibrary("Copy_if version: " + Copy_if_version::GetVersion());
  a.AddLibrary("Counter version: " + Counter::GetVersion());
  a.AddLibrary("CreateQtProjectZipFile version: " + CreateQtProjectZipFile::MenuDialog().GetVersion());
  a.AddLibrary("DasWahreSchlagerfest version: " + dws::MenuDialog().GetVersion());
  a.AddLibrary("Dial version: " + Dial::GetVersion());
  a.AddLibrary("DialWidget version: " + DialWidget::GetVersion());
  a.AddLibrary("DnaR version: " + ribi::DnaR().GetVersion());
  a.AddLibrary("DotMatrixChar version: " + DotMatrixChar::GetVersion());
  a.AddLibrary("DotMatrixString version: " + DotMatrixString::GetVersion());
  a.AddLibrary("DotMatrixText version: " + DotMatrixText::GetVersion());
  a.AddLibrary("DrawCanvas version: " + DrawCanvas::GetVersion());
  a.AddLibrary("Encranger (class) version: " + Encranger::GetVersion());
  a.AddLibrary("Encranger (tool) version: " + ToolEncrangerMenuDialog().GetVersion());
  a.AddLibrary("Exercise version: " + Exercise::GetVersion());
  a.AddLibrary("FileIo version: " + fileio::FileIo().GetVersion());
  a.AddLibrary("foam::Mesh version: " + ribi::foam::Mesh::GetVersion());
  a.AddLibrary("Fuzzy_equal_to version: " + fuzzy_equal_to::GetVersion());
  a.AddLibrary("GaborFilter version: " + GaborFilter::GetVersion());
  a.AddLibrary("GaborFilterWidget version: " + GaborFilterWidget::GetVersion());
  a.AddLibrary("Geometry version: " + Geometry().GetVersion());
  a.AddLibrary("Help version: " + Help::GetVersion());
  //a.AddLibrary("Hometrainer version: " + HometrainerMenuDialog().GetVersion());
  a.AddLibrary("HtmlPage version: " + HtmlPage::GetVersion());
  a.AddLibrary("ImageCanvas version: " + ImageCanvas::GetVersion());
  a.AddLibrary("IpAddress version: " + IpAddress::GetVersion());
  a.AddLibrary("K3OpEenRij version: " + K3OpEenRijMenuDialog().GetVersion());
  a.AddLibrary("kalman::FixedLagSmootherKalmanFilter version: " + kalman::FixedLagSmootherKalmanFilter::GetVersion());
  a.AddLibrary("kalman::KalmanFilter version: " + kalman::KalmanFilter::GetVersion());
  a.AddLibrary("kalman::LaggedWhiteNoiseSystem version: " + kalman::LaggedWhiteNoiseSystem::GetVersion());
  a.AddLibrary("kalman::StandardKalmanFilter version: " + kalman::StandardKalmanFilter::GetVersion());
  a.AddLibrary("kalman::StandardKalmanFilterParameters version: " + kalman::StandardKalmanFilterParameters::GetVersion());
  a.AddLibrary("kalman::StandardWhiteNoiseSystem version: " + kalman::StandardWhiteNoiseSystem::GetVersion());
  a.AddLibrary("kalman::StandardWhiteNoiseSystemParameters version: " + kalman::StandardWhiteNoiseSystemParameters::GetVersion());
  a.AddLibrary("kalman::SteadyStateKalmanFilter version: " + kalman::SteadyStateKalmanFilter::GetVersion());
  a.AddLibrary("kalman::SteadyStateKalmanFilterParameters version: " + kalman::SteadyStateKalmanFilterParameters::GetVersion());
  a.AddLibrary("kalman::WhiteNoiseSystem version: " + kalman::WhiteNoiseSystem::GetVersion());
  a.AddLibrary("Lazy_init version: " + Lazy_initVersion::GetVersion());
  a.AddLibrary("Led version: " + Led::GetVersion());
  a.AddLibrary("LedWidget version: " + LedWidget::GetVersion());
  a.AddLibrary("LoopReader version: " + LoopReader<int>::GetVersion());
  a.AddLibrary("ManyDigitNewick version: " + ManyDigitNewick::GetVersion());
  a.AddLibrary("Matrix version: " + Matrix::GetVersion());
  a.AddLibrary("Maziak version: " + maziak::MenuDialog().GetVersion());
  a.AddLibrary("MultiAlphaFilter version: " + MultiAlphaFilter::GetVersion());
  a.AddLibrary("MultiApproximator version: " + MultiApproximator<double,double>::GetVersion());
  a.AddLibrary("MultipleChoiceQuestion version: " + MultipleChoiceQuestion::GetVersion());
  a.AddLibrary("MultipleChoiceQuestionDialog version: " + MultipleChoiceQuestionDialog::GetVersion());
  a.AddLibrary("MultiVector version: " + MultiVector<int>::GetVersion());
  a.AddLibrary("Music::Chord version: " + Music::Chord::GetVersion());
  a.AddLibrary("Music::Note version: " + Music::Note::GetVersion());
  a.AddLibrary("Music::Scale version: " + Music::Scale::GetVersion());
  a.AddLibrary("MysteryMachine version: " + MysteryMachine::GetVersion());
  a.AddLibrary("MysteryMachineWidget version: " + MysteryMachineWidget::GetVersion());
  a.AddLibrary("Newick version: " + Newick().GetVersion());
  a.AddLibrary("NewickUtils version: " + ribi::NewickUtils().GetVersion());
  a.AddLibrary("NewickVector version: " + NewickVector::GetVersion());
  a.AddLibrary("OpenQuestion version: " + OpenQuestion::GetVersion());
  a.AddLibrary("OpenQuestionDialog version: " + OpenQuestionDialog::GetVersion());
  const std::unique_ptr<Plane> plane(
    new Plane(
      Plane::Coordinat3D(0.0,0.0,0.0),
      Plane::Coordinat3D(1.0,0.0,0.0),
      Plane::Coordinat3D(0.0,1.0,0.0)
    )
  );
  assert(plane);
  a.AddLibrary("PhylogenyR version: " + ribi::PhylogenyR().GetVersion());
  a.AddLibrary("Plane version: " + plane->GetVersion());
  a.AddLibrary("PolyFile version: " + PolyFile::GetVersion());
  a.AddLibrary("PolyFileFromPolygons version: " + PolyFileFromPolygons::GetVersion());
  a.AddLibrary("Pylos version: " + pylos::MenuDialog().GetVersion());
  a.AddLibrary("QmakeWatcher version: " + QmakeWatcherMenuDialog().GetVersion());
  a.AddLibrary("QrcFile version: " + QrcFile::GetVersion());
  a.AddLibrary("QtCreatorProFile version: " + QtCreatorProFile::GetVersion());
  a.AddLibrary("QtStdVectorFunctionModel version: " + QtStdVectorFunctionModel::GetVersion());
  a.AddLibrary("QtStdVectorStringModel version: " + QtStdVectorStringModel::GetVersion());
  a.AddLibrary("QtUblasMatrixDoubleModel version: " + QtUblasMatrixDoubleModel::GetVersion());
  a.AddLibrary("QtUblasVectorDoubleModel version: " + QtUblasVectorDoubleModel::GetVersion());
  a.AddLibrary("QtUblasVectorIntModel version: " + QtUblasVectorIntModel::GetVersion());
  a.AddLibrary("Question version: " + Question::GetVersion());
  a.AddLibrary("QuestionDialog version: " + QuestionDialog::GetVersion());
  a.AddLibrary("Rainbow version: " + Rainbow::GetVersion());
  a.AddLibrary("RandomCode version: " + RandomCode::GetVersion());
  a.AddLibrary("RegexTester version: " + RegexTesterMenuDialog().GetVersion());
  a.AddLibrary("Reversi (game) version: " + reversi::MenuDialog().GetVersion());
  a.AddLibrary("reversi::Board version: " + reversi::Board::GetVersion());
  a.AddLibrary("reversi::Widget version: " + reversi::Widget::GetVersion());
  a.AddLibrary("RichelBilderbeekProgram version: " + Program::GetVersion());
  a.AddLibrary("Rinside version: " + ribi::Rinside().GetVersion());
  a.AddLibrary("RubiksClock (class) version: " + ruco::Clock::GetVersion());
  a.AddLibrary("RubiksClock (game) version: " + ruco::MenuDialog().GetVersion());
  a.AddLibrary("RubiksClockDialversion: " + ruco::ClockDial::GetVersion());
  a.AddLibrary("RubiksClockDialWidget version: " + ruco::ClockDialWidget::GetVersion());
  a.AddLibrary("RubiksClockWidget version: " + ruco::ClockWidget::GetVersion());

#ifdef INCLUDE_SADD_20140617
  a.AddLibrary("SearchAndDestroyChess version: " + sadc::MenuDialog().GetVersion());
#endif // INCLUDE_SADD_20140617

  a.AddLibrary("Shape version: " + Shape::GetVersion());
  a.AddLibrary("ShapeWidget version: " + ShapeWidget::GetVersion());
  //a.AddLibrary("SimPredator version: " + SimPredatorMenuDialog().GetVersion());
  a.AddLibrary("ShinyButton version: " + ShinyButton::GetVersion());
  a.AddLibrary("ShinyButtonWidget version: " + ShinyButtonWidget::GetVersion());
  a.AddLibrary("SimMysteryMachine version: " + SimMysteryMachineMenuDialog().GetVersion());
  a.AddLibrary("SimpleLinearRegression version: " + SimpleLinearRegression::GetVersion());
  a.AddLibrary("SortedBinaryNewickVector version: " + SortedBinaryNewickVector::GetVersion());
  //a.AddLibrary("SpaceHarry version: " + SpaceHarryMenuDialog().GetVersion());
  a.AddLibrary("StaircaseCardCreator version: " + scc::MenuDialog().GetVersion());
  a.AddLibrary("StateObserver version: " + StateObserverMenuDialog().GetVersion());
  a.AddLibrary("Stopwatch version: " + Stopwatch::GetVersion());
  a.AddLibrary("TankBattalion version: " + taba::MenuDialog().GetVersion());
  a.AddLibrary("TestApproximator version: " + ToolTestApproximatorMenuDialog().GetVersion());
  a.AddLibrary("TestDial version: " + TestDialMenuDialog().GetVersion());
  a.AddLibrary("TestExercise version: " + TestExerciseMenuDialog().GetVersion());
  a.AddLibrary("TestFunctionParser version: " + TestFunctionParserMenuDialog().GetVersion());
  a.AddLibrary("TestLed version: " + TestLedMenuDialog().GetVersion());
  a.AddLibrary("TestMultiApproximator version: " + ToolTestMultiApproximatorMenuDialog().GetVersion());
  a.AddLibrary("TestNewickVector version: " + TestNewickVectorMenuDialog().GetVersion());
  a.AddLibrary("TestPolyFile version: " + TestPolyFileMenuDialog().GetVersion());
  a.AddLibrary("TestPolyFileFromPolygons version: " + TestPolyFileFromPolygonsMenuDialog().GetVersion());
  a.AddLibrary("TestProFile version: " + TestQtCreatorProFileMenuDialog().GetVersion());
  a.AddLibrary("TestQrcFile version: " + TestQrcFileMenuDialog().GetVersion());
  //a.AddLibrary("TestQuestion version: " + TestQuestionMenuDialog().GetVersion());
  a.AddLibrary("TestShape version: " + TestShapeMenuDialog().GetVersion());
  a.AddLibrary("TestShinyButton version: " + TestShinyButtonMenuDialog().GetVersion());
  a.AddLibrary("TestSimpleLinearRegression version: " + ToolTestSimpleLinearRegressionMenuDialog().GetVersion());
  a.AddLibrary("TestToggleButton version: " + TestToggleButtonMenuDialog().GetVersion());
  a.AddLibrary("Triangle version 1.6, by Jonathan Richard Shewchuk (http://www.cs.cmu.edu/~quake/triangle.html)");
  a.AddLibrary("TriangleFile version: " + TriangleFile::GetVersion());
  a.AddLibrary("TriangleMeshCreator version: " + TriangleMeshCreatorMenuDialog().GetVersion());
  a.AddLibrary("TextCanvas version: " + TextCanvas::GetVersion());
  a.AddLibrary("TicTacToe (game) version: " + tictactoe::TicTacToeMenuDialog().GetVersion());
  a.AddLibrary("TicTacToe version: " + tictactoe::Board::GetVersion());
  a.AddLibrary("ToggleButton version: " + ToggleButton::GetVersion());
  a.AddLibrary("ToggleButtonWidget version: " + ToggleButtonWidget::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());
  a.AddLibrary("Tron version: " + TronMenuDialog().GetVersion());
  a.AddLibrary("TwoDigitNewick version: " + TwoDigitNewick::GetVersion());
  a.AddLibrary("Warp's FunctionParser version: 4.4.3");
  a.AddLibrary("Widget version: " + Widget::GetVersion());
  a.AddLibrary("WktToSvg version: " + WktToSvgMenuDialog().GetVersion());
  a.AddLibrary("XeNonZero version: " + XeNonZeroMenuDialog().GetVersion());
  a.AddLibrary("XML version: " + ribi::xml::GetVersion());
  return a;
}
Ejemplo n.º 29
0
void Renderer::beginDraw(pgn::Window* wnd, RendererConfig* _cfg)
{
	cfg = *_cfg;

	for (int i = 0; i < numPasses; i++)
		isPassActive[i] = false;

	for (int i = 0; i < cfg.numActivePasses; i++)
		isPassActive[cfg.activePasses[i]] = true;

	pgn::Display display = wnd->getDisplay();

	rc->beginDraw(display, 2);
	rs = pgn::RenderingSystem::create(rc);

	resLoader = pgn::createAsyncLoader(rc, rs, display);
	geomMgr = pgn::ResourceManager::create(pnmFactory, assetStream, resLoader);
	editableGeomMgr = pgn::ResourceManager::create(editablePnmFactory, assetStream, resLoader);
	navGeomMgr = pgn::ResourceManager::create(navFactory, assetStream, resLoader);
	texMgr = pgn::ResourceManager::create(pntFactory, assetStream, resLoader);

	// 创建灰色纹理
	{
		unsigned char level0[][4] =
		{
			127, 127, 127, 255
		};

		void* levels[] =
		{
			level0
		};

		pgn::TextureDesc texDesc;
		texDesc.format = pgn::RGBA8;
		texDesc.width = 1;
		texDesc.height = 1;
		texDesc.numLevels = sizeof(levels) / sizeof(levels[0]);

		pgn::Texture* tex = rs->createTexture(&texDesc, levels);
		gray = texMgr->addResource("gray", tex);
	}

	// 创建黑色纹理
	{
		unsigned char level0[][4] =
		{
			0, 0, 0, 255
		};

		void* levels[] =
		{
			level0
		};

		pgn::TextureDesc texDesc;
		texDesc.format = pgn::RGBA8;
		texDesc.width = 1;
		texDesc.height = 1;
		texDesc.numLevels = sizeof(levels) / sizeof(levels[0]);

		pgn::Texture* tex = rs->createTexture(&texDesc, levels);
		black = texMgr->addResource("black", tex);
	}

	GeometryHelper helper(rs);

	// 创建screen-aligned quad
	{
		float pos[][2] =
		{
			-1.0f, -1.0f,
			1.0f, -1.0f,
			1.0f, 1.0f,
			-1.0f, 1.0f
		};

		float tc[][2] =
		{
			0.0f, 1.0f,
			1.0f, 1.0f,
			1.0f, 0.0f,
			0.0f, 0.0f
		};

		unsigned short indices[] =
		{
			0, 1, 2,
			2, 3, 0
		};

		int numIndices[] =
		{
			sizeof(indices) / sizeof(short)
		};

		pgn::VertexAttribDesc vertAttribDescs[] =
		{
			"position2D", pgn::FLOAT2, 0,
			"texCoord0", pgn::FLOAT2, 0
		};

		void* attribs[] =
		{
			pos, tc
		};

		Geometry* geom = debug_new Geometry(subsetAllocator);

		helper.createGeometry(
			geom,
			sizeof(vertAttribDescs) / sizeof(pgn::VertexAttribDesc),
			vertAttribDescs,
			sizeof(pos) / sizeof(pos[0]),
			sizeof(numIndices) / sizeof(numIndices[0]),
			numIndices,
			attribs,
			indices
			);

		geom->primType = pgn::PrimType::TRIANGLE_LIST;
		geom->skeletonTemplate = 0;
		geom->brdfCoeffBuf.buf = 0;

		screenAlignedQuad = geomMgr->addResource("screen-aligned quad", geom);
	}

	// 创建球体
	{
		#define patchPoints(segs) (3 + ((segs) + 4) * ((segs) - 1) / 2)

		const int segs = 2;

		const int innerPoints = patchPoints(segs - 3);
		const int outerPoints = patchPoints(segs) - innerPoints;
		const int patchVerts = 3;
		const int edgePoints = outerPoints - patchVerts;
		const int spherePoints = patchVerts * 20 / 5 + edgePoints * 20 / 2 + innerPoints * 20;

		const int patchFaces = (1 + (1 + 2 * (segs - 1))) / 2 * segs;
		const int sphereFaces = patchFaces * 20;

		float pos[spherePoints][3];
		unsigned short indices[sphereFaces * 3];

		const double phi = 1.618033988749895;
		const double icosaVerts[12][3] =
		{
			1.0, phi, 0.0,

			-1.0, phi, 0.0,
			-phi, 0.0, -1.0,
			0.0, 1.0, -phi,
			0.0, -1.0, -phi,
			phi, 0.0, -1.0,
			1.0, -phi, 0.0,
			phi, 0.0, 1.0,
			0.0, -1.0, phi,
			0.0, 1.0, phi,
			-phi, 0.0, 1.0,

			-1.0, -phi, 0.0,
		};

		static int icosaFaces[20][3] =
		{
			0, 1, 3,
			0, 3, 5,
			0, 5, 7,
			0, 7, 9,
			0, 9, 1,

			1, 2, 3,
			4, 3, 2,
			3, 4, 5,
			6, 5, 4,
			5, 6, 7,
			8, 7, 6,
			7, 8, 9,
			10, 9, 8,
			9, 10, 1,
			2, 1, 10,

			11, 4, 2,
			11, 6, 4,
			11, 8, 6,
			11, 10, 8,
			11, 2, 10
		};

		int numVerts = 0;

		auto addPoint = [&](float x, float y, float z)
		{
			int i;

			for (i = 0; i < numVerts; i++)
			{
				float dx = x - pos[i][0];
				float dy = y - pos[i][1];
				float dz = z - pos[i][2];

				if (dx < 0.0f) dx = -dx;
				if (dy < 0.0f) dy = -dy;
				if (dz < 0.0f) dz = -dz;

				if (dx < 0.0001f && dy < 0.0001f && dz < 0.0001f) break;
			}

			if (i == numVerts)
			{
				pos[i][0] = x;
				pos[i][1] = y;
				pos[i][2] = z;

				numVerts++;
			}

			return i;
		};

		int _numIndices = 0;

		for (auto patch : icosaFaces)
		{
			int pointIndices[patchPoints(segs)];
			int numPoints = 0;

			for (int i = 0; i <= segs; i++)
			{
				double a[3], b[3];

				double t = double(i) / double(segs);
				double k0 = 1.0 - t;
				double k1 = t;

				a[0] = k0 * icosaVerts[patch[0]][0] + k1 * icosaVerts[patch[1]][0];
				a[1] = k0 * icosaVerts[patch[0]][1] + k1 * icosaVerts[patch[1]][1];
				a[2] = k0 * icosaVerts[patch[0]][2] + k1 * icosaVerts[patch[1]][2];

				b[0] = k0 * icosaVerts[patch[0]][0] + k1 * icosaVerts[patch[2]][0];
				b[1] = k0 * icosaVerts[patch[0]][1] + k1 * icosaVerts[patch[2]][1];
				b[2] = k0 * icosaVerts[patch[0]][2] + k1 * icosaVerts[patch[2]][2];

				for (int j = 0; j <= i; j++)
				{
					double t = i ? double(j) / double(i) : 0.0;
					double k0 = 1.0 - t;
					double k1 = t;

					double x = k0 * a[0] + k1 * b[0];
					double y = k0 * a[1] + k1 * b[1];
					double z = k0 * a[2] + k1 * b[2];

					double r = sqrt(x*x + y*y + z*z);
					double invR = 1.0 / r;
					x *= invR;
					y *= invR;
					z *= invR;

					pointIndices[numPoints++] = addPoint((float)x, (float)y, (float)z);
				}
			}

			for (int i = 0; i < segs; i++)
			{
				int index0, index1, index2;

				for (int j = 0; j < 2 * i + 1; j++)
				{
					if (j % 2 == 0)
					{
						index0 = (i*i + i) / 2 + j / 2;
						index1 = index0 + i + 1;
						index2 = index1 + 1;
					}
					else
					{
						index1 = index0 + 1;
						std::swap(index0, index2);
					}

					indices[_numIndices++] = pointIndices[index0];
					indices[_numIndices++] = pointIndices[index1];
					indices[_numIndices++] = pointIndices[index2];
				}
			}
		}

		int numIndices[] =
		{
			sizeof(indices) / sizeof(short)
		};

		pgn::VertexAttribDesc vertAttribDescs[] =
		{
			"position", pgn::FLOAT3, 0,
		};

		void* attribs[] =
		{
			pos
		};

		Geometry* geom = debug_new Geometry(subsetAllocator);

		helper.createGeometry(
			geom,
			sizeof(vertAttribDescs) / sizeof(pgn::VertexAttribDesc),
			vertAttribDescs,
			sizeof(pos) / sizeof(pos[0]),
			sizeof(numIndices) / sizeof(numIndices[0]),
			numIndices,
			attribs,
			indices
			);

		geom->primType = pgn::PrimType::TRIANGLE_LIST;
		geom->skeletonTemplate = 0;
		geom->brdfCoeffBuf.buf = 0;

		sphere = geomMgr->addResource("sphere", geom);
	}

	for (auto& resView : resViews)
		resView = 0;

	for (int i = 0; i < cfg.numActivePasses; i++)
	{
		PassEnum pass = cfg.activePasses[i];
		EnvDesc* envDesc = envDescs[pass];
		Env* env = &envs[pass];

		for (int j = 0; j < envDesc->numOffscreenRTs; j++)
		{
			RenderTargetDesc* desc = &envDesc->offscreenRTDescs[j];
			ResourceView* view = resViews[desc->resViewEnum];

			if (!view)
			{
				view = debug_new ResourceView;
				resViews[desc->resViewEnum] = view;
			}

			RenderTarget rt;
			rt.view = view;
			rt.clearNeeded = desc->clearNeeded;
			rt.clearValue[0] = desc->clearValue[0];
			rt.clearValue[1] = desc->clearValue[1];
			rt.clearValue[2] = desc->clearValue[2];
			rt.clearValue[3] = desc->clearValue[3];

			env->offscreenRTs.push_back(rt);
		}

		if (envDesc->offscreenDepthStencilBufDesc)
		{
			DepthStencilBufDesc* desc = envDesc->offscreenDepthStencilBufDesc;
			ResourceView* view = resViews[desc->resViewEnum];

			if (!view)
			{
				view = debug_new ResourceView;
				resViews[desc->resViewEnum] = view;
			}

			DepthStencilBuf rt;
			rt.view = view;
			rt.depthClearNeeded = desc->depthClearNeeded;
			rt.depthClearValue = desc->depthClearValue;
			rt.stencilClearNeeded = desc->stencilClearNeeded;
			rt.stencilClearValue = desc->stencilClearValue;

			env->depthStencilBuf = rt;
		}
		else
		{
			env->depthStencilBuf.view = 0;
		}

		int numConsts = envDesc->numConsts;

		if (numConsts)
		{
			env->consts = debug_new EnvConst*[numConsts];

			int sizeCBuf = 0;

			for (int i = 0; i < numConsts; i++)
			{
				EnvConst* envConst = &envConsts[envDesc->constEnums[i]];
				env->consts[i] = envConst;
				sizeCBuf += envConst->size;
			}

			env->sizeCBuf = sizeCBuf;
		}

		env->numConsts = numConsts;
	}

	for (int i = 0; i < numResViews; i++)
	{
		ResourceView* view = resViews[i];

		if (!view) continue;

		ResourceViewDesc* desc = resViewDescs[i];

		view->type = desc->type;
		view->bindingPointName = desc->bindingPointName;
		view->resName = desc->resName;
		view->tex = rs->createTexture(desc->texDesc);
		view->texHandle = texMgr->addResource(view->resName, view->tex);

		switch (desc->type)
		{
		case RENDER_TARGET_VIEW:
			view->view = rs->createRenderTargetView(view->tex);
			break;
		case DEPTH_STENCIL_VIEW:
			view->view = rs->createDepthStencilView(view->tex);
			break;
		}

		view->autoSizeScale = desc->autoSizeScale;

		texBindingPointMap[view->bindingPointName] = view->tex;
	}

	bool programsReady = false;
	static char cacheFileName[] = "shaders.bin";

	if (/*cacheStream*/0)
	{
		cacheStream->open(cacheFileName, pgn::FileStream::in);

		if (cacheStream->isOpen())
		{
			long long cacheFileSize = cacheStream->getSize();
			char* cacheFileBuf = debug_new char[cacheFileSize];

			cacheStream->read(cacheFileBuf, cacheFileSize);
			cacheStream->close();

			programsReady = buildPrograms(cacheFileBuf);

			delete[] cacheFileBuf;
		}
Ejemplo n.º 30
0
int main(int argc, char** argv)
{
	int x = 0, y = 0, sample = 0, subpixel = 0;
	int i = 1;
	while (true)
	{
		if (i >= argc) break;

		if (std::string(argv[i]).compare("-x") == 0)
		{
			i++;
			x = atoi(argv[i]);
			i++;
			continue;
		}

		if (std::string(argv[i]).compare("-y") == 0)
		{
			i++;
			y = atoi(argv[i]);
			i++;
			continue;
		}

		if (std::string(argv[i]).compare("-s") == 0)
		{
			i++;
			sample = atoi(argv[i]);
			i++;
			continue;
		}

		if (std::string(argv[i]).compare("-p") == 0)
		{
			i++;
			subpixel = atoi(argv[i]);
			i++;
			continue;
		}

	}

	if (x == 0 || y == 0 || sample == 0 || subpixel == 0)
	{
		std::cout << "argv error. using default setting." << std::endl;
		x = 640;
		y = 480;
		sample = 4;
		subpixel = 2;
	}

	std::cout << "width:" << x << std::endl;
	std::cout << "height:" << y << std::endl;
	std::cout << "sample:" << sample << std::endl;
	std::cout << "subpixel:" << subpixel << std::endl;

	Setting render_settings(x, y, sample, subpixel);
	Camera cam(Imath::V3d(50.0, 52.0, 220.0), Imath::V3d(0.0, -0.04, -30.0).normalized(), Imath::V3d(0.0, -1.0, 0.0));
	Screen screen(cam, render_settings);
	ImageBuffer image(render_settings.reso_w * render_settings.reso_h);

	//Mesh mesh = Mesh();
	//mesh.push_back(Triangle(Imath::V3d(12.8, 5.0, -10), Imath::V3d(5.0, 20.0, -10), Imath::V3d(20.0, 20.0, -10)));
	//Geometry geom(mesh, Imath::V3d(0, 0, 0), Imath::C3f(0.7, 0.5, 0.5));
	//Geometry geom(mesh, Imath::V3d(0, 0, 0), Imath::C3f(0.7, 0.5, 0.5));
	Scene scene;
	//scene.geometries.push_back(geom);
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(1e5 + 1, 40.8, 81.6),		1e5),	Imath::V3d(1e5 + 1, 40.8, 81.6),	Imath::C3f(0.75, 0.25, 0.25), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(-1e5 + 99, 40.8, 81.6),	1e5),	Imath::V3d(-1e5 + 99, 40.8, 81.6),	Imath::C3f(0.25, 0.25, 0.75), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(50, 40.8, 1e5),			1e5),	Imath::V3d(50, 40.8, 1e5),			Imath::C3f(0.75, 0.75, 0.75), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(50, 40.8, -1e5 + 250),	1e5),	Imath::V3d(50, 40.8, -1e5 + 250),	Imath::C3f(0.0,  0.0,  0.0), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(50, 1e5, 81.6),			1e5),	Imath::V3d(50, 1e5, 81.6),			Imath::C3f(0.75, 0.75, 0.75), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(50, -1e5 + 81.6, 81.6),	1e5),	Imath::V3d(50, -1e5 + 81.6, 81.6),	Imath::C3f(0.75, 0.75, 0.75), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(65, 20, 20),				20),	Imath::V3d(65, 20, 20),				Imath::C3f(0.25, 0.75, 0.25), Imath::C3f(0, 0, 0), Reflection::Diffuse));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(27, 16.5, 47),			16.5),	Imath::V3d(27, 16.5, 47),			Imath::C3f(0.99, 0.99, 0.99), Imath::C3f(0, 0, 0), Reflection::Specular));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(77, 16.5, 78),			16.5),	Imath::V3d(77, 16.5, 78),			Imath::C3f(0.99, 0.99, 0.99), Imath::C3f(0, 0, 0), Reflection::Refraction));
	scene.geometries.push_back(Geometry(Sphere(Imath::V3d(50, 90, 81.6),			15.0),	Imath::V3d(50, 90, 81.6),			Imath::C3f(0.0,  0.0,  0.0), Imath::C3f(36, 36, 36), Reflection::Diffuse));
	//scene.geometries.push_back(Geometry(Triangle(Imath::V3d(12.8, 5.0, -10), Imath::V3d(5.0, 20.0, -10), Imath::V3d(20.0, 20.0, -10)), Imath::V3d(65, 20, 20), Imath::C3f(0.75, 0.75, 0.75), Imath::C3f(0, 0, 0), Reflection::Diffuse));

	render(render_settings,cam,screen,scene,image);
	write_bmp("out_complete.bmp", image, render_settings);
	return 0;
}