Пример #1
0
			inline SPROUT_CONSTEXPR FloatType
			copysign(FloatType x, FloatType y) {
				return x == 0
						? y == 0 ? y
							: sprout::math::signbit(y) ? -FloatType(0)
							: FloatType(0)
					: sprout::math::isnan(x)
						? sprout::math::isnan(y) ? y
							: sprout::math::signbit(y) ? -sprout::numeric_limits<FloatType>::quiet_NaN()
							: sprout::numeric_limits<FloatType>::quiet_NaN()
					: sprout::math::signbit(y) != sprout::math::signbit(x) ? -x
					: x
					;
			}
Пример #2
0
		inline SPROUT_CONSTEXPR FloatType
		str_to_float_impl_exponent_1(
			CStrIterator str,
			bool negative,
			FloatType number = FloatType(),
			std::size_t num_digits = 0,
			std::size_t num_decimals = 0,
			long exponent = 0,
			long n = 0
			)
		{
			typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
			return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
					sprout::next(str),
					negative,
					number,
					num_digits,
					num_decimals,
					exponent,
					n * 10 + (*str - static_cast<char_type>('0'))
					)
				: sprout::detail::str_to_float_impl_exponent_2<FloatType>(
					str,
					negative,
					number,
					num_digits,
					num_decimals,
					negative ? exponent + n : exponent - n
					)
				;
		}
Пример #3
0
		inline SPROUT_CONSTEXPR FloatType
		str_to_float_impl_exponent_2(
			CStrIterator str,
			bool negative,
			FloatType number = FloatType(),
			std::size_t num_digits = 0,
			std::size_t num_decimals = 0,
			long exponent = 0,
			long n = 0
			)
		{
			return exponent >= std::numeric_limits<FloatType>::min_exponent
				&& exponent <= std::numeric_limits<FloatType>::max_exponent
				? sprout::detail::str_to_float_impl_scale<FloatType>(
					str,
					negative,
					number,
					num_digits,
					num_decimals,
					exponent,
					exponent < 0 ? -exponent : exponent
					)
				: HUGE_VAL
				;
		}
Пример #4
0
		inline SPROUT_CONSTEXPR FloatType
		str_to_float_impl(
			CStrIterator str,
			bool negative,
			FloatType number = FloatType(),
			std::size_t num_digits = 0
			)
		{
			typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
			return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl<FloatType>(
					sprout::next(str),
					negative,
					number * 10 + (*str - static_cast<char_type>('0')),
					num_digits + 1
					)
				: *str == static_cast<char_type>('.') ? sprout::detail::str_to_float_impl_decimal<FloatType>(
					sprout::next(str),
					negative,
					number,
					num_digits
					)
				: sprout::detail::str_to_float_impl_decimal_1<FloatType>(
					str,
					negative,
					number,
					num_digits
					)
				;
		}
Пример #5
0
			inline SPROUT_CONSTEXPR FloatType
			acosh(FloatType x) {
				return x == 1 ? FloatType(0)
					: x < 1 ? std::numeric_limits<FloatType>::quiet_NaN()
					: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
					: sprout::math::log(x + sprout::math::sqrt(x * x - 1))
					;
			}
Пример #6
0
	TriMesh<FloatType> Shapes<FloatType>::torus(const vec3<FloatType> &center, FloatType majorRadius, FloatType minorRadius, UINT stacks, UINT slices, const std::function<vec4<FloatType>(unsigned int)> &stackIndexToColor)
	{
		std::vector<typename TriMesh<FloatType>::Vertex> vertices(slices * stacks);
		std::vector<UINT> indices(stacks * slices * 6);

		UINT vIndex = 0;
		// initial theta faces y front
		FloatType baseTheta = ml::math::PIf / 2.0f;
		for (UINT i = 0; i < stacks; i++)
		{
			FloatType theta = FloatType(i) * 2.0f * ml::math::PIf / FloatType(stacks) + baseTheta;
			auto color = stackIndexToColor(i);
			FloatType sinT = sinf(theta);
			FloatType cosT = cosf(theta);
			ml::vec3<FloatType> t0(cosT * majorRadius, sinT * majorRadius, 0.0f);
			for (UINT i2 = 0; i2 < slices; i2++)
			{
				auto& vtx = vertices[vIndex++];

				FloatType phi = FloatType(i2) * 2.0f * ml::math::PIf / FloatType(slices);
				FloatType sinP = sinf(phi);
				vtx.position = ml::vec3<FloatType>(minorRadius * cosT * sinP, minorRadius * sinT * sinP, minorRadius * cosf(phi)) + t0;
				vtx.color = color;
			}
		}

		UINT iIndex = 0;
		for (UINT i = 0; i < stacks; i++)
		{
			UINT ip1 = (i + 1) % stacks;
			for (UINT i2 = 0; i2 < slices; i2++)
			{
				UINT i2p1 = (i2 + 1) % slices;

				indices[iIndex++] = ip1 * slices + i2;
				indices[iIndex++] = i * slices + i2;
				indices[iIndex++] = i * slices + i2p1;

				indices[iIndex++] = ip1 * slices + i2;
				indices[iIndex++] = i * slices + i2p1;
				indices[iIndex++] = ip1 * slices + i2p1;
			}
		}

		return TriMesh<FloatType>(vertices, indices, true);
	}
Пример #7
0
void render(const std::vector<Intersecter *> &objects)
{
   unsigned width = 640, height = 480;
   Vector3 *image = new Vector3[width * height], *pixel = image;
   FloatType invWidth = 1 / FloatType(width), invHeight = 1 / FloatType(height);
   FloatType fov = 30, aspectratio = width / FloatType(height);
   FloatType angle = tan(M_PI * 0.5 * fov / FloatType(180));
   // Trace rays
   for (unsigned y = 0; y < height; ++y) {
      for (unsigned x = 0; x < width; ++x, ++pixel) {
         FloatType xx = (2 * ((x + 0.5) * invWidth) - 1) * angle * aspectratio;
         FloatType yy = (1 - 2 * ((y + 0.5) * invHeight)) * angle;
         Vector3 raydir(xx, yy, -1);
         raydir.normalize();
         *pixel = trace(Vector3(0), raydir, objects, 0);
      }
   }
   // Save result to a PPM image (keep these flags if you compile under Windows)
   std::ofstream ofs("./untitled.ppm", std::ios::out | std::ios::binary);
   ofs << "P6\n" << width << " " << height << "\n255\n";
   for (unsigned i = 0; i < width * height; ++i) {
      ofs << (unsigned char)(std::min(FloatType(1), image[i].x) * 255) << 
         (unsigned char)(std::min(FloatType(1), image[i].y) * 255) <<
         (unsigned char)(std::min(FloatType(1), image[i].z) * 255); 
   }
   ofs.close();
   delete [] image;
}
Пример #8
0
		inline SPROUT_CONSTEXPR FloatType
		float2_significand(FloatType x) {
			return sprout::math::isnan(x) ? x
				: x == sprout::numeric_limits<FloatType>::infinity() ? sprout::numeric_limits<FloatType>::infinity()
				: x == -sprout::numeric_limits<FloatType>::infinity() ? -sprout::numeric_limits<FloatType>::infinity()
				: x == 0 ? x
				: x / sprout::detail::pow_n(FloatType(2), sprout::float2_exponent(x))
				;
		}
Пример #9
0
			inline SPROUT_CONSTEXPR FloatType
			fmod(FloatType x, FloatType y) {
				return x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity() || y == 0
						? std::numeric_limits<FloatType>::quiet_NaN()
					: x == 0 ? FloatType(0)
					: y == std::numeric_limits<FloatType>::infinity() || y == -std::numeric_limits<FloatType>::infinity() ? x
					: x - sprout::math::trunc(x / y) * y
					;
			}
Пример #10
0
NEIGHAND_INLINE void NeighborhoodHandler<NEIGHAND_TEMPLATE_ARGUMENTS>::updateWeightBaseTables() {

    // maintain weighting tables: see neighand_apply.hpp for formula
    // Cube
    FloatType cellLoad = FloatType(numProxies) / FloatType(WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume);
    weightCubeWithLoad = weightCube * (1.0f + 1.52f * cellLoad);
    // Sphere
    for (uint32_t d32=0; d32<=maxWorldDist32; ++d32) {
        weightSphereTableBase[d32] = volumeSphereTable[d32] * (2.0f + helper.getSphereWeightingLoadFactor(d32)*cellLoad) + 10.0f;
        weightSphereTable[d32] = weightSphere * weightSphereTableBase[d32];
    }
    // Model premature stopping ability of Sphere by estimating
    // how many cells are processed on average for K objects.
    // This is an underestimate, but a fast one.
    // ignore weightLoadFactor: would have to compute equivalent d32, plus this kind of compensate the previous underestimate
    // One may always change weightSphere if that's not enough.
    for (uint32_t K=1; K<256; ++K) {
        FloatType eqV = K * FloatType(WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume) / FloatType(numProxies);
        weightSphereTableClosestBase[K] = eqV * (2.0f + cellLoad) + 10.0f;
        weightSphereTableClosest[K] = weightSphere * weightSphereTableClosestBase[K];
    }
    // NonEmpty
    for (uint32_t d32=0; d32<=maxWorldDist32; ++d32) {
        FloatType minV = d32*0.03125f; // d
        minV *= minV*minV * 4.1888f; // 4/3 pi d^3
        if (minV > WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume) minV = WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume;
        //weightNonEmptyTableBase[d32] = 1.0f + 2.0f * cellLoad * minV / WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume;
        weightNonEmptyTableBase[d32] = 2.0f * numProxies * minV / WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume;
        weightNonEmptyTable[d32] = weightNonEmpty * weightNonEmptyTableBase[d32];
    }
    // Brute
    for (uint32_t d32=0; d32<=maxWorldDist32; ++d32) {
        FloatType minV = d32*0.03125f; // d
        minV *= minV*minV * 4.1888f; // 4/3 pi d^3
        if (minV > WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume) minV = WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume;
        //weightBruteTableBase[d32] = cellLoad * minV / WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume;
        weightBruteTableBase[d32] = numProxies * (1.0f + minV / WrapHelper<NEIGHAND_TEMPLATE_ARGUMENTS>::MaxVolume);
        // Force selection of Brute when there is no object
        if (numProxies==0) weightBruteTableBase[d32] = -1.0f;
        weightBruteTable[d32] = weightBrute * weightBruteTableBase[d32];
    }

    updateWeightBaseTablesNeeded = false;
}
Пример #11
0
		FloatType operator()(FloatType t) const noexcept
		{
			return
				t < FloatType(0.0) ? FloatType(0) :
				t > FloatType(1.0) ? FloatType(1) :
				t < FloatType(0.5) ? InCircular<FloatType>()(t*2)/2 :
				(OutCircular<FloatType>()(t*2 - FloatType(1)) + FloatType(1))/2;
		}
Пример #12
0
		constexpr FloatType operator()(FloatType t) const noexcept
		{
			return
				t < FloatType(0.0) ? FloatType(0) :
				t > FloatType(1.0) ? FloatType(1) :
				t < FloatType(0.5) ? InQuartic<FloatType>()(t*2)/2 :
				(OutQuartic<FloatType>()(t*2 - FloatType(1)) + FloatType(1))/2;
		}
Пример #13
0
		FloatType operator()(FloatType t) const noexcept
		{
			return
				t < FloatType(0.0) ? FloatType(0) :
				t > FloatType(1.0) ? FloatType(1) :
				t < FloatType(0.5) ? InExponential<FloatType>()(t*2)/2 :
				(OutExponential<FloatType>()(t*2 - FloatType(1)) + FloatType(1))/2;
		}
Пример #14
0
		inline SPROUT_CONSTEXPR FloatType
		copysign(FloatType x, FloatType y) {
			return
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
				sprout::math::detail::builtin_copysign(x, y)
#else
				x == 0
					? y == 0 ? y
						: sprout::math::signbit(y) ? -FloatType(0)
						: FloatType(0)
				: sprout::math::isnan(x)
					? sprout::math::isnan(y) ? y
						: sprout::math::signbit(y) ? -sprout::numeric_limits<FloatType>::quiet_NaN()
						: sprout::numeric_limits<FloatType>::quiet_NaN()
				: sprout::math::signbit(y) != sprout::math::signbit(x) ? -x
				: x
#endif
				;
		}
Пример #15
0
			inline SPROUT_CONSTEXPR FloatType
			ceil(FloatType x) {
				return x == 0 ? FloatType(0)
					: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
					: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
					: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
						? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ceil: large float rounding."), x)
					: x < 0 ? -static_cast<FloatType>(static_cast<std::uintmax_t>(-x))
					: sprout::math::detail::ceil_impl(x, static_cast<FloatType>(static_cast<std::uintmax_t>(x)))
					;
			}
Пример #16
0
		inline SPROUT_CONSTEXPR FloatType
		acos(FloatType x) {
			return sprout::math::isnan(x) ? x
				: sprout::math::fabs(x) > 1 ? sprout::numeric_limits<FloatType>::quiet_NaN()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
				: sprout::math::detail::builtin_acos(x)
#else
				: x == 1 ? FloatType(0)
				: static_cast<FloatType>(sprout::math::detail::acos_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
				;
		}
Пример #17
0
/*==============================================================================
 * FUNCTION:         RTLInstDict::partialType
 * OVERVIEW:         Scan the Exp* pointed to by exp; if its top level operator indicates even a partial type, then set
 *                      the expression's type, and return true
 * NOTE:             This version only inspects one expression
 * PARAMETERS:       exp - points to a Exp* to be scanned
 *                   ty - ref to a Type object to put the partial type into
 * RETURNS:          True if a partial type is found
 *============================================================================*/
bool RTLInstDict::partialType(Exp *exp, Type &ty)
{
    if (exp->isSizeCast()) {
        ty = IntegerType(((Const *)((Binary *)exp)->getSubExp1())->getInt());
        return true;
    }
    if (exp->isFltConst()) {
        ty = FloatType(64);
        return true;
    }
    return false;
}
Пример #18
0
		inline SPROUT_CONSTEXPR FloatType
		str_to_float_impl_decimal_1(
			CStrIterator str,
			bool negative,
			FloatType number = FloatType(),
			std::size_t num_digits = 0,
			std::size_t num_decimals = 0,
			long exponent = 0
			)
		{
			return num_digits == 0 ? FloatType()
				: sprout::detail::str_to_float_impl_exponent<FloatType>(
					str,
					negative,
					negative ? -number : number,
					num_digits,
					num_decimals,
					exponent
					)
				;
		}
Пример #19
0
 void MultiLayerMieApplied<FloatType>::GetFailed() {
   FloatType faild_x = 9.42477796076938;
   //FloatType faild_x = 9.42477796076937;
   std::complex<FloatType> z(faild_x, 0.0);
   std::vector<int> nmax_local_array = {20, 100, 500, 2500};
   for (auto nmax_local : nmax_local_array) {
     std::vector<std::complex<FloatType> > D1_failed(nmax_local + 1);
     // Downward recurrence for D1 - equations (16a) and (16b)
     D1_failed[nmax_local] = std::complex<FloatType>(0.0, 0.0);
     const std::complex<FloatType> zinv = std::complex<FloatType>(1.0, 0.0)/z;
     for (int n = nmax_local; n > 0; n--) {
       D1_failed[n - 1] = FloatType(n)*zinv - 1.0/(D1_failed[n] + FloatType(n)*zinv);
     }
     printf("Faild D1[0] from reccurence (z = %16.14f, nmax = %d): %g\n",
            faild_x, nmax_local, D1_failed[0].real());
   }
   printf("Faild D1[0] from continued fraction (z = %16.14f): %g\n", faild_x,
          calcD1confra(0,z).real());
   //D1[nmax_] = calcD1confra(nmax_, z);
 
   
 }
Пример #20
0
  void buildNormalizedData( FloatType *normalized_data, 
			    void *orig_data,
			    unsigned int nr_elements,
			    float scale,
			    float bias ) {
    A *d = (A*) orig_data;
    
    for (unsigned int i = 0; i < nr_elements; i++) {
      normalized_data[i] = 
	(d[ i ] / FloatType( numeric_limits<A >::max() ) ) * scale + bias;
      if( normalized_data[i] < 0 ) normalized_data[i] = 0;
    }
  }
Пример #21
0
inline SPROUT_CONSTEXPR FloatType
log10(FloatType x) {
    return sprout::math::isnan(x) ? x
           : x == 0 ? -sprout::numeric_limits<FloatType>::infinity()
           : x == sprout::numeric_limits<FloatType>::infinity() ? sprout::numeric_limits<FloatType>::infinity()
           : x < 0 ? sprout::numeric_limits<FloatType>::quiet_NaN()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
           : sprout::math::detail::builtin_log10(x)
#else
           : x == 1 ? FloatType(0)
           : static_cast<FloatType>(sprout::math::detail::log10_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x)))
#endif
           ;
}
Пример #22
0
		inline SPROUT_CONSTEXPR sprout::pair<int, FloatType>
		float_digits_impl_1(sprout::pair<int, FloatType> const& current, FloatType val, int n) {
			typedef sprout::pair<int, FloatType> type;
			return (val / current.second) < 1 ? current
				: n == 1 ? type(current.first + 1, current.second * FloatType(10))
				: sprout::detail::float_digits_impl_1(
					sprout::detail::float_digits_impl_1(
						current,
						val, n / 2
						),
					val, n - n / 2
					)
				;
		}
Пример #23
0
/******************************************************************************
* This is called when the user has clicked the "Save Data" button.
******************************************************************************/
void BinAndReduceModifierEditor::onSaveData()
{
	BinAndReduceModifier* modifier = static_object_cast<BinAndReduceModifier>(editObject());
	if(!modifier)
		return;

	if(modifier->binData().empty())
		return;

	QString fileName = QFileDialog::getSaveFileName(mainWindow(),
	    tr("Save Data"), QString(), 
        tr("Text files (*.txt);;All files (*)"));
	if(fileName.isEmpty())
		return;

	try {

		QFile file(fileName);
		if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
			throw Exception(tr("Could not open file for writing: %1").arg(file.errorString()));

		int binDataSizeX = std::max(1, modifier->numberOfBinsX());
		int binDataSizeY = std::max(1, modifier->numberOfBinsY());
        if (modifier->is1D()) binDataSizeY = 1;
		FloatType binSizeX = (modifier->xAxisRangeEnd() - modifier->xAxisRangeStart()) / binDataSizeX;
		FloatType binSizeY = (modifier->yAxisRangeEnd() - modifier->yAxisRangeStart()) / binDataSizeY;

		QTextStream stream(&file);
        if (binDataSizeY == 1) {
            stream << "# " << modifier->sourceProperty().name() << " bin size: " << binSizeX << endl;
			for(size_t i = 0; i < modifier->binData().size(); i++) {
                stream << (binSizeX * (FloatType(i) + 0.5f) + modifier->xAxisRangeStart()) << " " << modifier->binData()[i] << endl;
            }
        }
        else {
            stream << "# " << modifier->sourceProperty().name() << " bin size X: " << binDataSizeX << ", bin size Y: " << binDataSizeY << endl;
            for(int i = 0; i < binDataSizeY; i++) {
                for(int j = 0; j < binDataSizeX; j++) {
                    stream << modifier->binData()[i*binDataSizeX+j] << " ";
                }
                stream << endl;
            }
        }
	}
	catch(const Exception& ex) {
		ex.showError();
	}
}
Пример #24
0
AnyType TPTScriptInterface::eval(std::deque<String> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, ValueValue());
	String word = words->front(); words->pop_front();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		else if(word == "quit")
			return tptS_quit(words);
		break;
	case TypeNumber:
		return NumberType(parseNumber(word));
	case TypeFloat:
		return FloatType(atof(word.ToUtf8().c_str()));
	case TypePoint:
	{
		int x, y;
		if(String::Split comma = word.SplitNumber(x))
			if(comma.After().BeginsWith(","))
				if(comma.After().Substr(1).SplitNumber(y))
					return PointType(x, y);
		return PointType(0, 0);
	}
	case TypeString:
		return StringType(word);
	default:
		break;
	}
	return StringType(word);
}
AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
{
	if(words->size() < 1)
		return AnyType(TypeNull, ValueValue());
	std::string word = words->front(); words->pop_front();
	char * rawWord = (char *)word.c_str();
	ValueType wordType = testType(word);
	switch(wordType)
	{
	case TypeFunction:
		if(word == "set")
			return tptS_set(words);
		else if(word == "create")
			return tptS_create(words);
		else if(word == "delete" || word == "kill")
			return tptS_delete(words);
		else if(word == "load")
			return tptS_load(words);
		else if(word == "reset")
			return tptS_reset(words);
		else if(word == "bubble")
			return tptS_bubble(words);
		else if(word == "quit")
			return tptS_quit(words);
		break;
	case TypeNumber:
		return NumberType(parseNumber(rawWord));
	case TypeFloat:
		return FloatType(atof(rawWord));
	case TypePoint:
	{
		int pointX, pointY;
		sscanf(rawWord, "%d,%d", &pointX, &pointY);
		return PointType(pointX, pointY);
	}
	case TypeString:
		return StringType(word);
	}
	return StringType(word);
}
Пример #26
0
		inline SPROUT_CONSTEXPR FloatType
		str_to_float_impl_exponent(
			CStrIterator str,
			bool negative,
			FloatType number = FloatType(),
			std::size_t num_digits = 0,
			std::size_t num_decimals = 0,
			long exponent = 0
			)
		{
			typedef typename std::iterator_traits<CStrIterator>::value_type char_type;
			return (*str == static_cast<char_type>('e') || *str == static_cast<char_type>('E'))
				? *sprout::next(str) == static_cast<char_type>('-')
					? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
						sprout::next(str, 2),
						true,
						number,
						num_digits,
						num_decimals,
						exponent
						)
					: sprout::detail::str_to_float_impl_exponent_1<FloatType>(
						sprout::next(str, 2),
						false,
						number,
						num_digits,
						num_decimals,
						exponent
						)
				: sprout::detail::str_to_float_impl_exponent_2<FloatType>(
					str,
					negative,
					number,
					num_digits,
					num_decimals,
					exponent
					)
				;
		}
Пример #27
0
/******************************************************************************
* Determines the display color of a single particle.
******************************************************************************/
ColorA ParticleDisplay::particleColor(size_t particleIndex, ParticlePropertyObject* colorProperty, ParticleTypeProperty* typeProperty, ParticlePropertyObject* selectionProperty, ParticlePropertyObject* transparencyProperty)
{
	OVITO_ASSERT(colorProperty == nullptr || colorProperty->type() == ParticleProperty::ColorProperty);
	OVITO_ASSERT(typeProperty == nullptr || typeProperty->type() == ParticleProperty::ParticleTypeProperty);
	OVITO_ASSERT(selectionProperty == nullptr || selectionProperty->type() == ParticleProperty::SelectionProperty);
	OVITO_ASSERT(transparencyProperty == nullptr || transparencyProperty->type() == ParticleProperty::TransparencyProperty);

	// Check if particle is selected.
	if(selectionProperty) {
		OVITO_ASSERT(particleIndex < selectionProperty->size());
		if(selectionProperty->getInt(particleIndex))
			return selectionParticleColor();
	}

	ColorA c = defaultParticleColor();
	if(colorProperty) {
		// Take particle color directly from the color property.
		OVITO_ASSERT(particleIndex < colorProperty->size());
		c = colorProperty->getColor(particleIndex);
	}
	else if(typeProperty) {
		// Return color based on particle types.
		OVITO_ASSERT(particleIndex < typeProperty->size());
		ParticleType* ptype = typeProperty->particleType(typeProperty->getInt(particleIndex));
		if(ptype)
			c = ptype->color();
	}

	// Apply alpha component.
	if(transparencyProperty) {
		OVITO_ASSERT(particleIndex < transparencyProperty->size());
		c.a() = FloatType(1) - transparencyProperty->getFloat(particleIndex);
	}

	return c;
}
Пример #28
0
			inline SPROUT_CONSTEXPR FloatType
			fractional_part(FloatType x) {
				return x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
					: x == std::numeric_limits<FloatType>::quiet_NaN() ? std::numeric_limits<FloatType>::quiet_NaN()
					: x - sprout::math::integer_part(x)
					;
			}
Пример #29
0
		inline SPROUT_CONSTEXPR FloatType
		float_pow10(int exponent) {
			return sprout::detail::pow_n(FloatType(10), exponent);
		}
Пример #30
0
		inline SPROUT_CONSTEXPR FloatType
		fractional_part(FloatType x) {
			return sprout::math::isnan(x) ? x
				: x == sprout::numeric_limits<FloatType>::infinity() || x == -sprout::numeric_limits<FloatType>::infinity() ? sprout::math::copysign(FloatType(0), x)
				: x == 0 ? x
				: sprout::math::detail::fractional_part_impl(x, sprout::integer_part(x))
				;
		}