コード例 #1
0
std::list<KDPoint> translatePoints(std::list<KDPoint> &listPoints, KDPoint vectorPoint)
{
	std::list<KDPoint> translatedPoints;
	KDTransformation translate(CGAL::TRANSLATION, KDVector(vectorPoint.x(), vectorPoint.y(), vectorPoint.z()));
	std::list<KDPoint>::iterator vectorPointInter;
	for(vectorPointInter = listPoints.begin(); vectorPointInter != listPoints.end(); ++vectorPointInter)
	{
		KDPoint point = *vectorPointInter;
		translatedPoints.push_back(translate(point));
	}
	return translatedPoints;
}
コード例 #2
0
ファイル: context_text.cpp プロジェクト: Tilka/epsilon
void KDContext::writeChar(char character, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, bool transparentBackground) {
  if (character == '\n' || character == '\t') {
    return;
  }
  char firstCharacter = size == KDText::FontSize::Large ? BITMAP_LargeFont_FIRST_CHARACTER : BITMAP_SmallFont_FIRST_CHARACTER;
  int characterHeight = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT : BITMAP_SmallFont_CHARACTER_HEIGHT;
  int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;

  KDColor * characterBuffer = size == KDText::FontSize::Large ? largeCharacterBuffer : smallCharacterBuffer;

  KDRect absoluteRect = absoluteFillRect(KDRect(p, characterWidth, characterHeight));
  if (transparentBackground) {
    pullRect(absoluteRect, characterBuffer);
  }
  KDCoordinate startingI = m_clippingRect.x() - p.translatedBy(m_origin).x();
  KDCoordinate startingJ = m_clippingRect.y() - p.translatedBy(m_origin).y();
  startingI = startingI < 0 ? 0 : startingI;
  startingJ = startingJ < 0 ? 0 : startingJ;

  for (KDCoordinate j=0; j<absoluteRect.height(); j++) {
    for (KDCoordinate i=0; i<absoluteRect.width(); i++) {
      KDColor * currentPixelAdress = characterBuffer + i + absoluteRect.width()*j;         uint8_t intensity = 0;
      if (size == KDText::FontSize::Large) {
        intensity = bitmapLargeFont[(uint8_t)character-(uint8_t)firstCharacter][j + startingJ][i +startingI];
      } else {
       intensity = bitmapSmallFont[(uint8_t)character-(uint8_t)firstCharacter][j + startingJ][i +startingI];
      }
      KDColor backColor = transparentBackground ? *currentPixelAdress : backgroundColor;
      *currentPixelAdress = KDColor::blend(textColor, backColor, intensity);
    }
  }
  pushRect(absoluteRect, characterBuffer);
}
コード例 #3
0
std::list<KDPoint> randomPointsInBox(int numPoints, KDPoint min, KDPoint max)
{
	CGAL::Random_points_in_cube_3<KDPoint, Pt_creator> cubeRnd(1.0);
	std::list<KDPoint> randomPointsCube;
	CGAL::copy_n(cubeRnd, numPoints, std::back_inserter(randomPointsCube));

	std::list<KDPoint> randomPoints;
	std::list<KDPoint>::iterator pointsIter;
	for(pointsIter = randomPointsCube.begin(); pointsIter != randomPointsCube.end(); ++pointsIter)
	{
		KDPoint point = *pointsIter;

		KDTransformation translate(CGAL::TRANSLATION, KDVector(1.0, 1.0, 1.0));
		KDTransformation scale(CGAL::SCALING, 0.5);
		point = translate(point);
		point = scale(point);

		KDTransformation scaleToBox((max.x()-min.x()), 0, 0, 0, (max.y()-min.y()), 0, 0, 0, (max.z()-min.z()));
		KDTransformation translateToBox(CGAL::TRANSLATION, KDVector(min.x(), min.y(), min.z()));
		point = scaleToBox(point);
		point = translateToBox(point);

		randomPoints.push_back(point);
	}
	return randomPoints;
}
コード例 #4
0
std::list<KDPoint> randomPointsInConcaveSphere(int numPoints, double innerRadius, double outerRadius)
{
	CGAL::Random_points_in_sphere_3<KDPoint, Pt_creator> sphereRnd(outerRadius - innerRadius);
	std::list<KDPoint> innerRandomPoints;
	CGAL::copy_n(sphereRnd, numPoints, std::back_inserter(innerRandomPoints));

	std::list<KDPoint> randomPoints;
	std::list<KDPoint>::iterator pointsIter;
	for(pointsIter = innerRandomPoints.begin(); pointsIter != innerRandomPoints.end(); ++pointsIter)
	{
		KDPoint point = *pointsIter;
		KDVector vPoint1 = KDVector(point.x(), point.y(), point.z());
		KDVector vPoint1Unit = vPoint1 / CGAL::sqrt(vPoint1.squared_length());
		KDVector vPoint2 = vPoint1Unit * innerRadius;
		KDVector vPoint = vPoint1 + vPoint2;
		randomPoints.push_back(KDPoint(vPoint.x(), vPoint.y(), vPoint.z()));
	}
	return randomPoints;
}
コード例 #5
0
ファイル: context_text.cpp プロジェクト: Tilka/epsilon
KDPoint KDContext::writeString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, int maxLength, bool transparentBackground) {
  KDPoint position = p;
  int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;
  int characterHeight = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT: BITMAP_SmallFont_CHARACTER_HEIGHT;
  KDPoint characterSize(characterWidth, 0);

  const char * end = text+maxLength;
  while(*text != 0 && text != end) {
    writeChar(*text, position, size, textColor, backgroundColor, transparentBackground);
    if (*text == '\n') {
      position = KDPoint(0, position.y()+characterHeight);
    } else if (*text == '\t') {
      position = position.translatedBy(KDPoint(KDText::k_tabCharacterWidth*characterWidth, 0));
    } else {
      position = position.translatedBy(characterSize);
    }
    text++;
  }
  return position;
}
コード例 #6
0
std::list<KDPoint> randomPointsInSphereGaussianDistribution(int numPoints, double radius, double width)
{
	CGAL::Random_points_in_sphere_3<KDPoint, Pt_creator> sphereRnd(1.0);
	std::list<KDPoint> innerRandomPoints;
	CGAL::copy_n(sphereRnd, numPoints, std::back_inserter(innerRandomPoints));

	std::list<KDPoint> randomPoints;
	std::list<KDPoint>::iterator pointsIter;
	for(pointsIter = innerRandomPoints.begin(); pointsIter != innerRandomPoints.end(); ++pointsIter)
	{
		KDPoint point = *pointsIter;
		KDVector vPointR = KDVector(point.x(), point.y(), point.z());
		double r =  CGAL::sqrt(vPointR.squared_length());
		KDVector unitVector = vPointR / r;
		double gaussRadius = std::exp(-(width*r*r));
		KDTransformation scaleGauss(CGAL::SCALING, gaussRadius);
		KDTransformation scaleRadius(CGAL::SCALING, radius);
		KDPoint scaledPoint = scaleGauss(KDPoint(unitVector.x(), unitVector.y(), unitVector.z()));
		scaledPoint = scaleRadius(scaledPoint);
		randomPoints.push_back(scaledPoint);
	}
	return randomPoints;
}
コード例 #7
0
ファイル: bracket_pair_layout.cpp プロジェクト: Tilka/epsilon
void BracketPairLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
  const KDCoordinate k_widthMargin = widthMargin();
  const KDCoordinate k_externWidthMargin = externWidthMargin();
  KDSize operandSize = operandLayout()->size();
  KDCoordinate verticalBarHeight = operandLayout()->size().height() + 2*k_verticalMargin;
  ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y()+verticalExternMargin(), k_lineThickness, verticalBarHeight), expressionColor);
  ctx->fillRect(KDRect(p.x()+k_externWidthMargin+operandSize.width()+2*k_widthMargin+k_lineThickness, p.y()+verticalExternMargin(), k_lineThickness, verticalBarHeight), expressionColor);
  if (renderTopBar()) {
    ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y()+verticalExternMargin(), k_bracketWidth, k_lineThickness), expressionColor);
    ctx->fillRect(KDRect(p.x()+k_externWidthMargin+2*k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y() + verticalExternMargin(), k_bracketWidth, k_lineThickness), expressionColor);
  }
  if (renderBottomBar()) {
    ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y()+verticalExternMargin()+verticalBarHeight-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
    ctx->fillRect(KDRect(p.x()+k_externWidthMargin+2*k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y()+verticalExternMargin()+verticalBarHeight-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
  }
}
コード例 #8
0
void LeftParenthesisLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
  KDRect frame(p.x()+ParenthesisLayout::k_externWidthMargin,
      p.y()+ParenthesisLayout::k_externHeightMargin,
      ParenthesisLayout::k_parenthesisCurveWidth,
      ParenthesisLayout::k_parenthesisCurveHeight);

  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topLeftCurve, (KDColor *)(ParenthesisLayout::s_parenthesisWorkingBuffer));

  frame = KDRect(p.x()+ParenthesisLayout::k_externWidthMargin,
      p.y() + size().height() - ParenthesisLayout::k_parenthesisCurveHeight - ParenthesisLayout::k_externHeightMargin,
      ParenthesisLayout::k_parenthesisCurveWidth,
      ParenthesisLayout::k_parenthesisCurveHeight);

  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomLeftCurve, (KDColor *)(ParenthesisLayout::s_parenthesisWorkingBuffer));

  ctx->fillRect(KDRect(p.x()+ParenthesisLayout::k_externWidthMargin,
        p.y()+ParenthesisLayout::k_parenthesisCurveHeight+ParenthesisLayout::k_externHeightMargin,
        ParenthesisLayout::k_lineThickness,
        size().height() - 2*(ParenthesisLayout::k_parenthesisCurveHeight+ParenthesisLayout::k_externHeightMargin)),
      expressionColor);
}
コード例 #9
0
ファイル: context_line.cpp プロジェクト: Tilka/epsilon
void KDContext::drawLine(KDPoint p1, KDPoint p2, KDColor c) {
  // Find the largest gap
  KDPoint left = KDPointZero, right = KDPointZero;
  if (p2.x() > p1.x()) {
    left = p1;
    right = p2;
  } else {
    left = p2;
    right = p1;
  }
  KDPoint top = KDPointZero, bottom = KDPointZero;
  if (p2.y() > p1.y()) {
    top = p1;
    bottom = p2;
  } else {
    top = p2;
    bottom = p1;
  }
  assert(right.x() >= left.x());
  assert(bottom.y() >= top.y());

  KDCoordinate deltaX = 2*(right.x() - left.x());
  KDCoordinate deltaY = 2*(bottom.y() - top.y());

  KDPoint p = KDPointZero, alwaysTranslate = KDPointZero, conditionalTranslate = KDPointZero;
  KDCoordinate scanLength, error, minusError, plusError;

  if (deltaX >= deltaY) {
    p = left;
    scanLength = right.x() - left.x();
    error = right.x() - left.x();
    minusError = deltaY;
    plusError = deltaX;
    alwaysTranslate = KDPoint(1,0);
    conditionalTranslate = KDPoint(0, (right.y() >= left.y() ? 1 : -1));
  } else {
    p = top;
    scanLength = bottom.y() - top.y();
    error = bottom.y() - top.y();
    minusError = deltaX;
    plusError = deltaY;
    alwaysTranslate = KDPoint(0,1);
    conditionalTranslate = KDPoint((bottom.x() >= top.x() ? 1 : -1), 0);
  }

  KDCoordinate scanCounter = 0;
  while (scanCounter++ < scanLength) {
    setPixel(p, c);
    p = p.translatedBy(alwaysTranslate);
    error = error - minusError;
    if (error <= 0) {
      p = p.translatedBy(conditionalTranslate);
      error = error + plusError;
    }
  }
}
コード例 #10
0
ファイル: point.cpp プロジェクト: Tilka/epsilon
KDPoint KDPoint::translatedBy(KDPoint other) const {
  return KDPoint(m_x+other.x(), m_y+other.y());
}
コード例 #11
0
ファイル: point.cpp プロジェクト: Tilka/epsilon
uint16_t KDPoint::squareDistanceTo(KDPoint other) const {
    return (m_x-other.x()) * (m_x-other.x()) + (m_y-other.y()) * (m_y-other.y());
}
コード例 #12
0
//Call the rejointMesh in RejointMeshes.cpp on the meshes that have distance with targetPoint greater than double distance
// use isExternJoin = true to joint the extern meshes, use isExternJoin = false to joint the internal meshes
std::list<MeshData> rejointMeshesInDistance(std::list<MeshData> &listMeshData, KDPoint targetPoint, double distance, double isExternJoin)
{
	std::list<MeshData> result;
	std::list<MeshData> meshesToJoin;
	double squaredDistance = distance * distance;
	PointCGAL exactTargetPoint(targetPoint.x(), targetPoint.y(), targetPoint.z());

	std::list<MeshData>::iterator meshDataInter;
	for(meshDataInter = listMeshData.begin(); meshDataInter != listMeshData.end(); ++meshDataInter)
	{
		bool meshIsOutOfDistance = true; //Algorithm 1
		//bool meshIsOutOfDistance = false; //Algorithm 2
		std::list<Triangle>::iterator triangleIter;
		for(triangleIter = meshDataInter->first.begin(); triangleIter != meshDataInter->first.end(); ++triangleIter)
		{
			Triangle t = *triangleIter;

			//Algorithm 1: This algorithm excludes from the join the meshes on the radius
			for (int i = 0; i < 3; ++i)
			{
				PointCGAL tv = t.vertex(i);

				//it could be used a logic XNOR but it is not so understable, so I use this condition
				if (isExternJoin)
				{
					if (CGAL::squared_distance(tv, exactTargetPoint) < squaredDistance)
					{
						meshIsOutOfDistance = false;
					}
				}
				else
				{
					if (CGAL::squared_distance(tv, exactTargetPoint) > squaredDistance)
					{
						meshIsOutOfDistance = false;
					}
				}
			}
			if (!meshIsOutOfDistance)
			{
				break;
			}


			/*
			//Algorithm 2: This algorithm includes from the join the meshes on the radius
			//Ideale per pezzi piccoli e dominio dei punti voronoi dentro il raggio,
			// sembra funzionare solo per isExternJoin, TODO: test
			for (int i = 0; i < 3; ++i)
			{
				PointCGAL tv = t.vertex(i);

				if (isExternJoin)
				{
					if (CGAL::squared_distance(tv, exactTargetPoint) > squaredDistance)
					{
						meshIsOutOfDistance = true;
					}
				}
				else
				{
					if (CGAL::squared_distance(tv, exactTargetPoint) < squaredDistance)
					{
						meshIsOutOfDistance = true;
					}
				}
			}
			if (meshIsOutOfDistance)
			{
				break;
			}
			*/

		}

		if (meshIsOutOfDistance)
		{
			meshesToJoin.push_back(*meshDataInter);
		}
		else
		{
			result.push_back(*meshDataInter);
		}
	}

	if (meshesToJoin.size() > 0)
	{
		MeshData rejointMeshes = simpleRejointMeshes(meshesToJoin);
		//MeshData rejointMeshes = rejointMeshes(meshesToJoin);
		result.push_back(rejointMeshes);
	}

	std::cout << "Executed rejointMeshesInDistance: not joined meshes: " << (listMeshData.size() - meshesToJoin.size()) << ", joined meshes: " << meshesToJoin.size() << std::endl;

	return result;

}
コード例 #13
0
PointCGAL converPointInexactToExact(KDPoint point)
{
	return PointCGAL(CGAL::to_double(point.x()), CGAL::to_double(point.y()), CGAL::to_double(point.z()));
}
コード例 #14
0
void RightSquareBracketLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
  ctx->fillRect(KDRect(p.x()+k_widthMargin, p.y(), k_lineThickness, operandHeight()), expressionColor);
  ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y(), k_bracketWidth, k_lineThickness), expressionColor);
  ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y() + operandHeight(), k_bracketWidth, k_lineThickness), expressionColor);
}