summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-28 23:57:52 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-28 23:57:52 (GMT)
commit2b3c140bd264f8a5cf94d3fa83f875933fbb4928 (patch)
tree91a96f286fe13d6530de513faa53249a669da44c
parent6c3ce9934755bcc579ac30104d651608c2c71622 (diff)
parentda08b50c03418110a74a6f2667be1d916b607b87 (diff)
Merge branch 'master' into visitortests
Conflicts: tests/opencsgtest.cc
-rw-r--r--src/control.cc15
-rw-r--r--src/dxfdata.h2
-rw-r--r--testdata/scad/features/child-background.scad8
-rw-r--r--testdata/scad/features/highlight-and-background-modifier.scad8
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/imageutils-lodepng.cc22
-rw-r--r--tests/imageutils-macosx.cc63
-rw-r--r--tests/imageutils.cc16
-rw-r--r--tests/imageutils.h9
-rw-r--r--tests/regression/cgalpngtest/include-tests-expected.pngbin0 -> 11444 bytes
-rw-r--r--tests/regression/opencsgtest/highlight-and-background-modifier-expected.pngbin0 -> 21649 bytes
-rw-r--r--tests/regression/opencsgtest/include-tests-expected.pngbin0 -> 11994 bytes
12 files changed, 140 insertions, 6 deletions
diff --git a/src/control.cc b/src/control.cc
index 492b909..1f79254 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -91,6 +91,8 @@ void for_eval(AbstractNode &node, const ModuleInstantiation &inst, size_t l,
AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation *inst) const
{
+ AbstractNode *node = NULL;
+
if (type == CHILD)
{
size_t n = 0;
@@ -102,17 +104,20 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
for (int i = Context::ctx_stack.size()-1; i >= 0; i--) {
const Context *c = Context::ctx_stack[i];
if (c->inst_p) {
- if (n < c->inst_p->children.size())
- return c->inst_p->children[n]->evaluate(c->inst_p->ctx);
- return NULL;
+ if (n < c->inst_p->children.size()) {
+ node = c->inst_p->children[n]->evaluate(c->inst_p->ctx);
+ // FIXME: We'd like to inherit any tags from the ModuleInstantiation
+ // given as parameter to this method. However, the instantition which belongs
+ // to the returned node cannot be changed. This causes the test
+ // features/child-background.scad to fail.
+ }
+ return node;
}
c = c->parent;
}
return NULL;
}
- AbstractNode *node;
-
if (type == INT_FOR)
node = new AbstractIntersectionNode(inst);
else
diff --git a/src/dxfdata.h b/src/dxfdata.h
index 4e4b4ab..d8dc3dd 100644
--- a/src/dxfdata.h
+++ b/src/dxfdata.h
@@ -35,7 +35,7 @@ public:
}
};
- std::vector<Vector2d> points;
+ std::vector<Vector2d, Eigen::aligned_allocator<Vector2d> > points;
std::vector<Path> paths;
std::vector<Dim> dims;
diff --git a/testdata/scad/features/child-background.scad b/testdata/scad/features/child-background.scad
new file mode 100644
index 0000000..9923913
--- /dev/null
+++ b/testdata/scad/features/child-background.scad
@@ -0,0 +1,8 @@
+module transparent() {
+ %child();
+}
+
+difference() {
+ sphere(r=10);
+ transparent() cylinder(h=30, r=6, center=true);
+}
diff --git a/testdata/scad/features/highlight-and-background-modifier.scad b/testdata/scad/features/highlight-and-background-modifier.scad
new file mode 100644
index 0000000..945d6b4
--- /dev/null
+++ b/testdata/scad/features/highlight-and-background-modifier.scad
@@ -0,0 +1,8 @@
+difference() {
+ sphere(r=10);
+ %#cylinder(h=30, r=6, center=true);
+}
+translate([13,0,0]) difference() {
+ sphere(r=10);
+ #%cylinder(h=30, r=6, center=true);
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index dca608d..a0db0e4 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -291,6 +291,9 @@ add_cmdline_test(cgalpngtest png ${CGALPNGTEST_FILES})
# Add opencsg tests to CTest
LIST(APPEND OPENCSGTEST_FILES ${CGALPNGTEST_FILES})
+LIST(APPEND OPENCSGTEST_FILES
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/highlight-and-background-modifier.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/child-background.scad)
add_cmdline_test(opencsgtest png ${OPENCSGTEST_FILES})
# Add throwntogether tests to CTest
diff --git a/tests/imageutils-lodepng.cc b/tests/imageutils-lodepng.cc
new file mode 100644
index 0000000..98c48de
--- /dev/null
+++ b/tests/imageutils-lodepng.cc
@@ -0,0 +1,22 @@
+#include "lodepng.h"
+
+bool write_png(const char *filename, unsigned char *pixels, int width, int height)
+{
+ //encoder.settings.zlibsettings.windowSize = 2048;
+ //LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG");
+
+ size_t dataout_size = -1;
+ GLubyte *dataout = (GLubyte*)malloc(width*height*4);
+ LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
+ //LodePNG_saveFile(dataout, dataout_size, "blah2.png");
+ FILE *f = fopen(filename, "w");
+ if (!f) {
+ free(dataout);
+ return false;
+ }
+
+ fwrite(dataout, 1, dataout_size, f);
+ fclose(f);
+ free(dataout);
+ return true;
+}
diff --git a/tests/imageutils-macosx.cc b/tests/imageutils-macosx.cc
new file mode 100644
index 0000000..358bdcf
--- /dev/null
+++ b/tests/imageutils-macosx.cc
@@ -0,0 +1,63 @@
+#include <ApplicationServices/ApplicationServices.h>
+#include <iostream>
+
+bool write_png(const char *filename, unsigned char *pixels, int width, int height)
+{
+ size_t rowBytes = width * 4;
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+ CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big; // BGRA
+ int bitsPerComponent = 8;
+ CGContextRef contextRef = CGBitmapContextCreate(pixels, width, height,
+ bitsPerComponent, rowBytes,
+ colorSpace, bitmapInfo);
+ if (!contextRef) {
+ std::cerr << "Unable to create CGContextRef.";
+ return false;
+ }
+
+ CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
+ if (!imageRef) {
+ std::cerr << "Unable to create CGImageRef.";
+ return false;
+ }
+
+ CFStringRef fname = CFStringCreateWithCString(kCFAllocatorDefault, filename, kCFStringEncodingUTF8);
+ CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ fname, kCFURLPOSIXPathStyle, false);
+ if (!fileURL) {
+ std::cerr << "Unable to create file URL ref.";
+ return false;
+ }
+
+ CGDataConsumerRef dataconsumer = CGDataConsumerCreateWithURL(fileURL);
+ CFIndex fileImageIndex = 1;
+ CFMutableDictionaryRef fileDict = NULL;
+ CFStringRef fileUTType = kUTTypePNG;
+ // Create an image destination opaque reference for authoring an image file
+ CGImageDestinationRef imageDest = CGImageDestinationCreateWithDataConsumer(dataconsumer,
+ fileUTType,
+ fileImageIndex,
+ fileDict);
+ if (!imageDest) {
+ std::cerr << "Unable to create CGImageDestinationRef.";
+ return false;
+ }
+
+ CFIndex capacity = 1;
+ CFMutableDictionaryRef imageProps =
+ CFDictionaryCreateMutable(kCFAllocatorDefault,
+ capacity,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ CGImageDestinationAddImage(imageDest, imageRef, imageProps);
+ CGImageDestinationFinalize(imageDest);
+
+ CFRelease(imageDest);
+ CFRelease(dataconsumer);
+ CFRelease(fileURL);
+ CFRelease(fname);
+ CFRelease(imageProps);
+ CGColorSpaceRelease(colorSpace);
+ CGImageRelease(imageRef);
+ return true;
+}
diff --git a/tests/imageutils.cc b/tests/imageutils.cc
new file mode 100644
index 0000000..7358674
--- /dev/null
+++ b/tests/imageutils.cc
@@ -0,0 +1,16 @@
+#include "imageutils.h"
+#include <strings.h>
+
+void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height)
+{
+ size_t rowBytes = pixelsize * width;
+ for (size_t i = 0 ; i < height ; i++) {
+ bcopy(src + i * rowBytes, dst + (height - i - 1) * rowBytes, rowBytes);
+ }
+}
+
+#ifdef __APPLE__
+#include "imageutils-macosx.cc"
+#else
+#include "imageutils-lodepng.cc"
+#endif
diff --git a/tests/imageutils.h b/tests/imageutils.h
new file mode 100644
index 0000000..72602a2
--- /dev/null
+++ b/tests/imageutils.h
@@ -0,0 +1,9 @@
+#ifndef IMAGEUTILS_H_
+#define IMAGEUTILS_H_
+
+#include <stdlib.h>
+
+bool write_png(const char *filename, unsigned char *pixels, int width, int height);
+void flip_image(const unsigned char *src, unsigned char *dst, size_t pixelsize, size_t width, size_t height);
+
+#endif
diff --git a/tests/regression/cgalpngtest/include-tests-expected.png b/tests/regression/cgalpngtest/include-tests-expected.png
new file mode 100644
index 0000000..99ebcc7
--- /dev/null
+++ b/tests/regression/cgalpngtest/include-tests-expected.png
Binary files differ
diff --git a/tests/regression/opencsgtest/highlight-and-background-modifier-expected.png b/tests/regression/opencsgtest/highlight-and-background-modifier-expected.png
new file mode 100644
index 0000000..72d03c3
--- /dev/null
+++ b/tests/regression/opencsgtest/highlight-and-background-modifier-expected.png
Binary files differ
diff --git a/tests/regression/opencsgtest/include-tests-expected.png b/tests/regression/opencsgtest/include-tests-expected.png
new file mode 100644
index 0000000..62be03c
--- /dev/null
+++ b/tests/regression/opencsgtest/include-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum