gnu.trove.list.array.TFloatArrayList Java Examples

The following examples show how to use gnu.trove.list.array.TFloatArrayList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Convert.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param vertices vertices
 * @param triangleVertexLUT triangleVertexLUT
 *
 * @return vertices
 */
public static float[] convertFromLUT(
		final TFloatArrayList vertices,
		final ArrayList<TIntArrayList> triangleVertexLUT)
{

	final float[] export = new float[triangleVertexLUT.size() * 9];
	int           t      = -1;
	for (final TIntArrayList triangleVertices : triangleVertexLUT)
	{
		final TIntArrayList vertexIndices = triangleVertices;
		for (int i = 0; i < vertexIndices.size(); ++i)
		{
			int vertexIndex = vertexIndices.get(i) * 3;
			export[++t] = vertices.get(vertexIndex);
			export[++t] = vertices.get(++vertexIndex);
			export[++t] = vertices.get(++vertexIndex);
		}
	}
	return export;
}
 
Example #2
Source File: Smooth.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static float[] smooth(final float[] vertices, final double lambda, final int iterations)
{
	LOG.debug("Smoothing {} vertices with lambda={} and iterations={}", vertices.length, lambda, iterations);
	Triple<TFloatArrayList, ArrayList<TIntHashSet>, ArrayList<TIntArrayList>> luts               = Convert
			.convertToLUT(
			vertices);
	float[]                                                                   vertexCoordinates1 = luts.getA()
			.toArray();
	final ArrayList<TIntHashSet>                                              vertexTriangleLUT  = luts.getB();
	final ArrayList<TIntArrayList>                                            triangleVertexLUT  = luts.getC();
	final boolean[]                                                           boundaryVertices   =
			boundaryVertices(
			vertexTriangleLUT,
			triangleVertexLUT
	                                                                                                               );

	for (int iteration = 0; iteration < iterations; ++iteration)
	{
		float[] vertexCoordinates2 = new float[vertexCoordinates1.length];

		final double[]    vertexRef          = new double[3];
		final double[]    otherVertexRef     = new double[3];
		AtomicInteger     count              = new AtomicInteger(0);
		final TIntHashSet otherVertexIndices = new TIntHashSet();
		for (int vertexIndex = 0; vertexIndex < vertexTriangleLUT.size(); ++vertexIndex)
		{
			getVertex(vertexCoordinates1, vertexRef, vertexIndex);
			if (!boundaryVertices[vertexIndex])
			{
				final int fVertexIndex = vertexIndex;
				count.set(0);
				otherVertexIndices.clear();
				otherVertexRef[0] = 0;
				otherVertexRef[1] = 0;
				otherVertexRef[2] = 0;

				vertexTriangleLUT.get(vertexIndex).forEach(otherTriangleIndex ->
				{
					final TIntArrayList otherVertices = triangleVertexLUT.get(otherTriangleIndex);
					for (int k = 0; k < otherVertices.size(); ++k)
					{
						final int otherVertexIndex = otherVertices.get(k);
						if (otherVertexIndex != fVertexIndex)
							otherVertexIndices.add(otherVertexIndex);
					}
					return true;
				});

				final float[] fVertexCoordinates1 = vertexCoordinates1;

				otherVertexIndices.forEach(l -> {
					count.incrementAndGet();
					addVertex(fVertexCoordinates1, otherVertexRef, l);
					return true;
				});

				final double c = 1.0 / count.get();
				vertexRef[0] = (otherVertexRef[0] * c - vertexRef[0]) * lambda + vertexRef[0];
				vertexRef[1] = (otherVertexRef[1] * c - vertexRef[1]) * lambda + vertexRef[1];
				vertexRef[2] = (otherVertexRef[2] * c - vertexRef[2]) * lambda + vertexRef[2];

				//					System.out.println( "count = " + count.get() );
			}
			//				else
			//					System.out.println( "leaving boundary vertex untouched." );

			setVertex(vertexCoordinates2, vertexRef, vertexIndex);
		}
		vertexCoordinates1 = vertexCoordinates2;
	}

	return Convert.convertFromLUT(TFloatArrayList.wrap(vertexCoordinates1), triangleVertexLUT);
}
 
Example #3
Source File: Convert.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert a set of triangles defined by three vertices each into a reduced list of vertices and a LUT from vertex
 * index to triangle index and from triangle index to vertex index.
 *
 * @param triangles triangles
 *
 * @return ([vertices], [vertex-triangle-lookup], [triangle-vertex-lut])
 */
public static Triple<TFloatArrayList, ArrayList<TIntHashSet>, ArrayList<TIntArrayList>> convertToLUT(
		final float[] triangles)
{

	LOG.debug("Converting {} triangles to lut", triangles.length);

	assert triangles.length % 9 == 0;

	final TFloatArrayList            vertices          = new TFloatArrayList(); // stride 3
	final TObjectIntHashMap<Point3D> vertexIndexMap    = new TObjectIntHashMap<>();
	final ArrayList<TIntHashSet>     vertexTriangleLUT = new ArrayList<>();
	final ArrayList<TIntArrayList>   triangleVertexLUT = new ArrayList<>();

	for (int triangle = 0; triangle < triangles.length; triangle += 9)
	{
		final int triangleIndex = triangle / 9;

		final Point3D[] keys = new Point3D[] {
				new Point3D(triangles[triangle + 0], triangles[triangle + 1], triangles[triangle + 2]),
				new Point3D(triangles[triangle + 3], triangles[triangle + 4], triangles[triangle + 5]),
				new Point3D(triangles[triangle + 6], triangles[triangle + 7], triangles[triangle + 8])
		};

		final TIntArrayList vertexIndices = new TIntArrayList();
		triangleVertexLUT.add(vertexIndices);
		for (int i = 0; i < keys.length; ++i)
		{
			final Point3D key = keys[i];
			final int     vertexIndex;
			if (vertexIndexMap.contains(key))
				vertexIndex = vertexIndexMap.get(keys[i]);
			else
			{
				vertexIndex = vertices.size() / 3;
				vertexIndexMap.put(key, vertexIndex);
				vertices.add((float) key.getX());
				vertices.add((float) key.getY());
				vertices.add((float) key.getZ());
			}
			vertexIndices.add(vertexIndex);

			final TIntHashSet triangleIndices;
			if (vertexTriangleLUT.size() > vertexIndex)
			{
				triangleIndices = vertexTriangleLUT.get(vertexIndex);
			}
			else
			{
				triangleIndices = new TIntHashSet();
				vertexTriangleLUT.add(triangleIndices);
			}
			triangleIndices.add(triangleIndex);
		}
	}
	return new ValueTriple<>(
			vertices,
			vertexTriangleLUT,
			triangleVertexLUT
	);
}
 
Example #4
Source File: FloatVectorImpl.java    From cineast with MIT License 4 votes vote down vote up
public FloatVectorImpl(TFloatArrayList list) {
  this.list = list;
}
 
Example #5
Source File: FloatVectorImpl.java    From cineast with MIT License 4 votes vote down vote up
public FloatVectorImpl() {
  this(new TFloatArrayList());
}
 
Example #6
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TFloatArrayList price, int quantity, TLongArrayList priceTimeMillSec) {
	this( portfolio, assetName,  price.toArray(),  quantity,  priceTimeMillSec.toArray());
}
 
Example #7
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TFloatArrayList price, TLongArrayList priceTimeMillSec, TIntArrayList quantity, TLongArrayList quantityTimeMillSec) {
	this( portfolio,  assetName,  price.toArray(),  priceTimeMillSec.toArray(),  quantity.toArray(),  quantityTimeMillSec.toArray());
}
 
Example #8
Source File: Estimator.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric addIndex(TFloatArrayList indexPrice, long timeStepMilliSec) {
	return  addIndex(indexPrice.toArray(), timeStepMilliSec);
}
 
Example #9
Source File: Estimator.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric addIndex(TFloatArrayList price, TLongArrayList timeMilliSec) {
	return addIndex( price.toArray(),  timeMilliSec.toArray());
}
 
Example #10
Source File: Portfolio.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric addIndex(TFloatArrayList indexPrice, long timeStepMilliSec) {
	return  addIndex( indexPrice.toArray(),  timeStepMilliSec);
}
 
Example #11
Source File: Portfolio.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric addIndex(TFloatArrayList indexPrice, TLongArrayList timeStepMilliSec) {
	return  addIndex( indexPrice.toArray(),  timeStepMilliSec.toArray());
}