Merge branch 'master' into visitortests

Conflicts:
	tests/opencsgtest.cc
stl_dim
Marius Kintel 2011-09-29 01:57:52 +02:00
commit 2b3c140bd2
12 changed files with 140 additions and 6 deletions

View File

@ -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

View File

@ -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;

View File

@ -0,0 +1,8 @@
module transparent() {
%child();
}
difference() {
sphere(r=10);
transparent() cylinder(h=30, r=6, center=true);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

16
tests/imageutils.cc Normal file
View File

@ -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

9
tests/imageutils.h Normal file
View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB