#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "SubdivideEdges")
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/polyhedron.hole.k3d")
setup.source.center = False
setup.source.scale_to_size = False

selection = k3d.geometry.selection.create(0)
edge_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.EDGE)
k3d.geometry.primitive_selection.append(edge_selection, 0, 4294967295, 0)
k3d.geometry.primitive_selection.append(edge_selection, 0, 4, 1)
k3d.geometry.primitive_selection.append(edge_selection, 27, 28, 1)
k3d.geometry.primitive_selection.append(edge_selection, 52, 65, 1)
k3d.geometry.primitive_selection.append(edge_selection, 74, 82, 1)
setup.modifier.mesh_selection = selection
setup.modifier.vertices = 2

testing.require_valid_mesh(setup.document, setup.modifier.get_property("output_mesh"))
testing.require_similar_mesh(setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.SubdivideEdges", 8)

#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "SubdivideFaces")
# load a mesh that has multiple polyhedra, triangles, quads, n-sided polygons and holes. (i.e. a mesh from hell)
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/polyhedron.hole.k3d")
setup.source.center = False
setup.source.scale_to_size = False

#testing.add_point_attributes_test(setup, True, True, False)

# select some faces, distributed along polyhedra
selection = k3d.geometry.selection.create(0)
face_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.FACE)
k3d.geometry.primitive_selection.append(face_selection, 0, 6, 0)
k3d.geometry.primitive_selection.append(face_selection, 6, 7, 1)
k3d.geometry.primitive_selection.append(face_selection, 7, 8, 0)
k3d.geometry.primitive_selection.append(face_selection, 8, 9, 1)
k3d.geometry.primitive_selection.append(face_selection, 9, 13, 0)
k3d.geometry.primitive_selection.append(face_selection, 13, 15, 1)
k3d.geometry.primitive_selection.append(face_selection, 15, 16, 0)
k3d.geometry.primitive_selection.append(face_selection, 16, 17, 1)
k3d.geometry.primitive_selection.append(face_selection, 17, 19, 0)
k3d.geometry.primitive_selection.append(face_selection, 19, 20, 1)
k3d.geometry.primitive_selection.append(face_selection, 20, 23, 0)

setup.modifier.mesh_selection = selection
setup.modifier.subdivision_type = "centermidpoints"
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "BridgeEdges")
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/mesh.modifier.BridgeEdges.source.k3d")

selection = k3d.geometry.selection.create(0)
edge_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.EDGE)
k3d.geometry.primitive_selection.append(edge_selection, 1, 2, 1)
k3d.geometry.primitive_selection.append(edge_selection, 7, 8, 1)

setup.modifier.mesh_selection = selection


testing.require_valid_mesh(setup.document, setup.modifier.get_property("output_mesh"))
testing.require_similar_mesh(setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.BridgeEdges", 1)

Example #4
0
#python

import k3d
import testing

document = k3d.new_document()

reader = document.new_node("K3DMeshReader")
reader.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/testmesh.polyhedra.k3d")
reader.center = False
reader.scale_to_size = False

script_path = testing.source_path() + "/../share/scripts/MeshModifierScript/random_face_varying_colors.py"
script_file = open(script_path, "r")
script = ""
line = script_file.readline()
while line:
  script += line
  line = script_file.readline()
varying_colors = document.new_node("MeshModifierScript")
varying_colors.script = script

document.set_dependency(varying_colors.get_property("input_mesh"), reader.get_property("output_mesh"))

modifier = document.new_node("SubdivideEdges")
# select some edges, distributed along polyhedra
selection = k3d.mesh_selection.deselect_all()
selection.edges =[(0, 4294967295, 0), (0, 1, 1), (1, 2, 1), (2, 3, 1), (3, 4, 1), (52, 53, 1), (53, 54, 1), (54, 55, 1), (55, 56, 1), (56, 57, 1), (57, 58, 1), (58, 59, 1), (59, 60, 1), (60, 61, 1), (61, 62, 1), (62, 63, 1), (63, 64, 1), (64, 65, 1), (74, 75, 1), (75, 76, 1), (76, 77, 1), (77, 78, 1), (78, 79, 1), (79, 80, 1), (80, 81, 1), (81, 82, 1)]
modifier.mesh_selection = selection
modifier.vertices = 2
#python

import testing
import k3d

factories = k3d.plugin.factory.lookup()

for factory in factories:
    if factory.is_application_plugin() and ("DocumentImporter"
                                            in factory.name()):

        print "\n\nTesting " + factory.name(
        ) + " with a file containing all zeroes ..."
        path = k3d.filesystem.generic_path(testing.source_path() + "/meshes/" +
                                           "zero_bytes")
        document = k3d.new_document()
        document_importer = k3d.plugin.create(factory.name())
        document_importer.read_file(path, document)
        k3d.close_document(document)

        print "\n\nTesting " + factory.name(
        ) + " with a file containing random data ..."
        path = k3d.filesystem.generic_path(testing.source_path() + "/meshes/" +
                                           "random_bytes")
        document = k3d.new_document()
        document_importer = k3d.plugin.create(factory.name())
        document_importer.read_file(path, document)
        k3d.close_document(document)
#python

import k3d
import testing

document = k3d.new_document()

small_cylinder = k3d.plugin.create("PLYMeshReader", document)
small_cylinder.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/mesh.modifier.CARVEBoolean.input.b.ply")
small_cylinder.center = False
small_cylinder.scale_to_size = False
big_cylinder = k3d.plugin.create("PLYMeshReader", document)
big_cylinder.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/mesh.modifier.CARVEBoolean.input.a.ply")
big_cylinder.center = False
big_cylinder.scale_to_size = False

carve_boolean = k3d.plugin.create("CARVEBoolean", document)
carve_boolean.type = "difference"
k3d.property.create(carve_boolean, "k3d::mesh*", "input_1", "Input 1", "")
k3d.property.create(carve_boolean, "k3d::mesh*", "input_2", "Input 2", "")

k3d.property.connect(document, big_cylinder.get_property("output_mesh"), carve_boolean.get_property("input_1"))
k3d.property.connect(document, small_cylinder.get_property("output_mesh"), carve_boolean.get_property("input_2"))

testing.require_valid_mesh(document, carve_boolean.get_property("output_mesh"))
testing.require_similar_mesh(document, carve_boolean.get_property("output_mesh"), "mesh.modifier.CARVEBoolean.ply", 10)

# python

import testing
import k3d

factories = k3d.plugin.factory.lookup()

for factory in factories:
    if factory.is_application_plugin() and ("DocumentImporter" in factory.name()):

        print "\n\nTesting " + factory.name() + " with a file containing all zeroes ..."
        path = k3d.filesystem.generic_path(testing.source_path() + "/meshes/" + "zero_bytes")
        document = k3d.new_document()
        document_importer = k3d.plugin.create(factory.name())
        document_importer.read_file(path, document)
        k3d.close_document(document)

        print "\n\nTesting " + factory.name() + " with a file containing random data ..."
        path = k3d.filesystem.generic_path(testing.source_path() + "/meshes/" + "random_bytes")
        document = k3d.new_document()
        document_importer = k3d.plugin.create(factory.name())
        document_importer.read_file(path, document)
        k3d.close_document(document)
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("PLYMeshReader", "PGPRemesh")
setup.source.file = testing.source_path() + "/meshes/bun_zipper_res4.ply"
#setup.modifier.use_smooth = True
#setup.modifier.smooth_4 = False
#setup.modifier.steps = 5
#setup.modifier.h = 1500
#setup.modifier.omega = 10
#setup.modifier.div = 2

testing.require_valid_mesh(setup.document, setup.modifier.get_property("output_mesh"))
testing.require_similar_mesh(setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.PGPRemesh.bun_zipper_res4", 1)

Example #9
0
# Write the geometry to a temporary file ...
writer = doc.new_node("STLMeshWriter")
writer.file = file
doc.set_dependency(writer.get_property("input_mesh"),
                   source.get_property("output_mesh"))

# Read the geometry back in ...
reader = doc.new_node("STLMeshReader")
reader.file = file
reader.center = False
reader.scale_to_size = False

#read in the reference date. This differs from the source data, since the STL file format is incapable of preserving vertex order
reference = doc.new_node("K3DMeshReader")
reference.file = k3d.filesystem.generic_path(
    testing.source_path() +
    "/meshes/mesh.source.STLMeshReader.reference.1.k3d")
reference.center = False
reference.scale_to_size = False

# Compare the reference to the imported data ...
diff = doc.new_node("MeshDiff")
diff.create_property("k3d::mesh*", "input_a", "InputA", "First input mesh")
diff.create_property("k3d::mesh*", "input_b", "InputB", "Second input mesh")

doc.set_dependency(diff.get_property("input_a"),
                   reference.get_property("output_mesh"))
doc.set_dependency(diff.get_property("input_b"),
                   reader.get_property("output_mesh"))

if not diff.get_property("input_a").pipeline_value() or not diff.get_property(
# python

import k3d
import testing
import copy

source_file = "papagayo_example.dat"

setup = testing.setup_scalar_source_test("PapagayoLipsyncReader")

setup.source.frame_rate = 30
setup.source.interpolate = True
setup.source.interpolation_time = 0.2

setup.source.papagayo_file = k3d.filesystem.generic_path(testing.source_path() + "/lipsync/" + source_file)

test_cases = [
    [0.0, {"rest": 1.0}],
    [1.98, {"E": 0.24000000000000021, "etc": 0.75999999999999979}],
    [2.0, {"E": 0.5, "etc": 0.5}],
    [4.34, {"E": 0.69999999999999463, "MBP": 0.30000000000000537}],
]

mouths = ["AI", "E", "etc", "FV", "L", "MBP", "O", "rest", "U", "WQ"]

for test_case in test_cases:
    setup.source.time = test_case[0]
    source_mouth_value = 0.0
    mouths_in_zero = copy.deepcopy(mouths)
    for mouth, reference_value in test_case[1].iteritems():
        exec("source_mouth_value = setup.source." + mouth)
Example #11
0
#python

import k3d
import testing
import copy

source_file = "papagayo_example.dat"

setup = testing.setup_scalar_source_test("PapagayoLipsyncReader")

setup.source.frame_rate = 30
setup.source.interpolate = True
setup.source.interpolation_time = 0.2

setup.source.papagayo_file = k3d.filesystem.generic_path(
    testing.source_path() + "/lipsync/" + source_file)

test_cases = \
[
    [0.0,{"rest":1.0}],
    [1.98,{"E":0.24000000000000021,"etc":0.75999999999999979}],
    [2.0,{"E":0.5,"etc":0.5}],
    [4.34,{"E":0.69999999999999463,"MBP":0.30000000000000537}],
]

mouths = ["AI", "E", "etc", "FV", "L", "MBP", "O", "rest", "U", "WQ"]

for test_case in test_cases:
    setup.source.time = test_case[0]
    source_mouth_value = 0.0
    mouths_in_zero = copy.deepcopy(mouths)
Example #12
0
# An HTML table measurement
print """<DartMeasurement name="HTML Table" type="text/html"><![CDATA[
<table>
<tr><th>Time</th><th>Value 1</th><th>Value 2</th></tr>
<tr><td>1</td><td>1.2</td><td>1.6</td></tr>
<tr><td>2</td><td>1.3</td><td>2.4</td></tr>
<tr><td>3</td><td>1.4</td><td>4.5</td></tr>
<tr><td>4</td><td>1.5</td><td>8.9</td></tr>
</table>
]]></DartMeasurement>"""

# An HTML Google Chart measurement
print """<DartMeasurement name="HTML Chart" type="text/html"><![CDATA[
<img src="http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World">
]]></DartMeasurement>"""

# An arbitrary XML measurement
print """<DartMeasurement name="XML" type="text/xml"><![CDATA[
<foo><bar a="b"><baz c="d"/></bar></foo>
]]></DartMeasurement>"""

# JPEG image measurement
print """<DartMeasurementFile name="JPEG Image" type="image/jpeg">""" + testing.source_path() + """/bitmaps/test_rgb_8.jpg</DartMeasurementFile>"""

# PNG image measurement
print """<DartMeasurementFile name="PNG Image" type="image/png">""" + testing.source_path() + """/bitmaps/test_rgb_8.png</DartMeasurementFile>"""

sys.stdout.flush()

Example #13
0
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "MergeCollinearEdges")
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/mesh.modifier.MergeCoplanarFaces.reference.1.k3d")

setup.modifier.mesh_selection = k3d.mesh_selection.select_all()

testing.mesh_comparison_to_reference(setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.MergeCollinearEdges", 1)

Example #14
0
#python

import k3d
import testing

document = k3d.new_document()

reader = document.new_node("K3DMeshReader")
# load a mesh that has multiple polyhedra, triangles, quads, n-sided polygons and holes. (i.e. a mesh from hell)
reader.file = k3d.filesystem.generic_path(
    testing.source_path() + "/meshes/testmesh.polyhedra.hole.k3d")
reader.center = False
reader.scale_to_size = False

varying_colors = document.new_node("RandomColors")

document.set_dependency(varying_colors.get_property("input_mesh"),
                        reader.get_property("output_mesh"))

modifier = document.new_node("Delete")

# select some faces, distributed along polyhedra
selection = k3d.mesh_selection.deselect_all()
face_selection = k3d.mesh_selection.component(0, 1000,
                                              k3d.selection.type.UNIFORM)
face_selection.add_range(0, 6, 0)
face_selection.add_range(6, 7, 1)
face_selection.add_range(7, 8, 0)
face_selection.add_range(8, 9, 1)
face_selection.add_range(9, 13, 0)
face_selection.add_range(13, 15, 1)
Example #15
0
#python

import testing
import k3d

factories = k3d.plugin.factory.lookup()

failing_document_importers = ""

doc = None

for factory in factories :
	if factory.is_application_plugin() and ("DocumentImporter" in factory.name()):
		try:
			document_importer = k3d.plugin.create(factory.name())
			path = k3d.filesystem.generic_path(testing.source_path() + "/meshes/" + "mesh.source.MeshReaders.bogus_input")
			doc = k3d.new_document()
			document_importer.read_file(doc,path)
			k3d.close_document(doc)
			doc = None
		except:
			failing_document_importers += factory.name() + " "
			if doc != None:
				k3d.close_document(doc)

if failing_document_importers != "":
	raise Exception(failing_document_importers + "failed to load a bogus input")
Example #16
0
# An HTML table measurement
print """<DartMeasurement name="HTML Table" type="text/html"><![CDATA[
<table>
<tr><th>Time</th><th>Value 1</th><th>Value 2</th></tr>
<tr><td>1</td><td>1.2</td><td>1.6</td></tr>
<tr><td>2</td><td>1.3</td><td>2.4</td></tr>
<tr><td>3</td><td>1.4</td><td>4.5</td></tr>
<tr><td>4</td><td>1.5</td><td>8.9</td></tr>
</table>
]]></DartMeasurement>"""

# An HTML Google Chart measurement
print """<DartMeasurement name="HTML Chart" type="text/html"><![CDATA[
<img src="http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World">
]]></DartMeasurement>"""

# An arbitrary XML measurement
print """<DartMeasurement name="XML" type="text/xml"><![CDATA[
<foo><bar a="b"><baz c="d"/></bar></foo>
]]></DartMeasurement>"""

# JPEG image measurement
print """<DartMeasurementFile name="JPEG Image" type="image/jpeg">""" + testing.source_path(
) + """/bitmaps/test_rgb_8.jpg</DartMeasurementFile>"""

# PNG image measurement
print """<DartMeasurementFile name="PNG Image" type="image/png">""" + testing.source_path(
) + """/bitmaps/test_rgb_8.png</DartMeasurementFile>"""

sys.stdout.flush()
Example #17
0
#python

import k3d
import testing

document = k3d.new_document()

reader = document.new_node("K3DMeshReader")
# load a mesh that has multiple polyhedra, triangles, quads, n-sided polygons and holes. (i.e. a mesh from hell)
reader.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/testmesh.polyhedra.hole.k3d")
reader.center = False
reader.scale_to_size = False

varying_colors = document.new_node("RandomColors")

document.set_dependency(varying_colors.get_property("input_mesh"), reader.get_property("output_mesh"))

modifier = document.new_node("CatmullClark")
# select some faces, distributed along polyhedra
selection = k3d.mesh_selection.deselect_all()
selection.faces = [(0, 6, 0), (6, 7, 1), (7, 8, 0), (8, 9, 1), (9, 13, 0), (13, 15, 1), (15, 16, 0), (16, 17, 1), (17, 19, 0), (19, 20, 1), (20, 23, 0)]
modifier.mesh_selection = selection
modifier.level = 2

document.set_dependency(modifier.get_property("input_mesh"), varying_colors.get_property("output_mesh"))

testing.mesh_comparison_to_reference(document, modifier.get_property("output_mesh"), "mesh.modifier.CatmullClark.complex", 2)
Example #18
0
#python

import k3d
import testing

document = k3d.new_document()

reader = document.new_node("PLYMeshReader")
reader.file = testing.source_path() + "/meshes/bun_zipper_res4.ply"

modifier = document.new_node("PGPRemesh")
#modifier.use_smooth = True
#modifier.smooth_4 = False
#modifier.steps = 5
#modifier.h = 1500
#modifier.omega = 10
#modifier.div = 2
document.set_dependency(modifier.get_property("input_mesh"),
                        reader.get_property("output_mesh"))

testing.mesh_comparison_to_reference(
    document, modifier.get_property("output_mesh"),
    "mesh.modifier.PGPRemesh.bun_zipper_res4", 1)
#python

import k3d
import testing

setup = testing.setup_bitmap_modifier_test("BitmapReader", "BitmapMatteColorDiff")
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/bitmaps/" + "test_rgb_8_alpha.png")
setup.modifier.threshold = 0.95

testing.require_similar_bitmap(setup.document, setup.modifier.get_property("output_bitmap"), "BitmapMatteColorDiff", 0)
Example #20
0
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "BridgeFaces")
setup.source.file = k3d.filesystem.generic_path(
    testing.source_path() + "/meshes/mesh.modifier.BridgeFaces.source.k3d")

selection = k3d.geometry.selection.create(0)
edge_selection = k3d.geometry.primitive_selection.create(
    selection, k3d.selection.type.FACE)
k3d.geometry.primitive_selection.append(edge_selection, 8, 9, 1)
k3d.geometry.primitive_selection.append(edge_selection, 12, 13, 1)

setup.modifier.mesh_selection = selection

testing.require_valid_mesh(setup.document,
                           setup.modifier.get_property("output_mesh"))
testing.require_similar_mesh(setup.document,
                             setup.modifier.get_property("output_mesh"),
                             "mesh.modifier.BridgeFaces", 1)
#python

import k3d
import testing

setup = testing.setup_bitmap_modifier_test("BitmapReader", "BitmapSubtract")
setup.source.file = k3d.filesystem.generic_path(testing.source_path() +
                                                "/bitmaps/" + "test_rgb_8.png")
setup.modifier.value = 0.5

testing.require_similar_bitmap(setup.document,
                               setup.modifier.get_property("output_bitmap"),
                               "BitmapSubtract", 0.001)
Example #22
0
#python

import k3d
import testing

document = k3d.new_document()

reader = document.new_node("K3DMeshReader")

reader.file = k3d.filesystem.generic_path(testing.source_path() +
                                          "/meshes/testmesh.polyhedra.k3d")

modifier = document.new_node("CUDASubdivideEdges")
# select some edges, distributed along polyhedra
selection = k3d.mesh_selection.deselect_all()
selection.edges = [(0, 4294967295, 0), (0, 1, 1), (1, 2, 1), (2, 3, 1),
                   (3, 4, 1), (52, 53, 1), (53, 54, 1), (54, 55, 1),
                   (55, 56, 1), (56, 57, 1), (57, 58, 1), (58, 59, 1),
                   (59, 60, 1), (60, 61, 1), (61, 62, 1), (62, 63, 1),
                   (63, 64, 1), (64, 65, 1), (74, 75, 1), (75, 76, 1),
                   (76, 77, 1), (77, 78, 1), (78, 79, 1), (79, 80, 1),
                   (80, 81, 1), (81, 82, 1)]
modifier.mesh_selection = selection
modifier.vertices = 2

document.set_dependency(modifier.get_property("input_mesh"),
                        reader.get_property("output_mesh"))

testing.mesh_comparison_to_reference(document,
                                     modifier.get_property("output_mesh"),
                                     "mesh.modifier.SubdivideEdges", 1)