use <../../curves/nSplines-2019/files/splines.scad> use <../../curves/nSplines-2019/files/Naca_sweep.scad> use <../line-tracing/line-tracing-v8.scad> //use <./building-geometry-from-traces-flat_image_pane-v13.scad> use <../image-in-polygon/show_image_in_polygon-v15.scad> //A photo image is used to supply a polygon trace, drawn in a 4-pixel wide color line. //Typically this polygon is drawn on top of the image of interest, and saved as // a separate trace .png file. //This image is processed by png-rcol.py, // python3 png-rcol.py xx1.png > xx1.txt // png-rcol.py names the openscad array the same as the .png file name, with // "-" changed to "_". include <./demo_image_tiger_trace-outer.txt>; trace0 = demo_image_in_poly_tiger_trace_outer; TTx = len(trace0[0]); // num x pixels of image containing color trace echo("tiger trace image data has pixels X, Y", TTx, len(trace0)); //get trace line reference colors from lower left corner boxes RefColorsForTraceSearch = LT_ColorTraceList(trace0, [1, len(trace0)-1-1] ); echo("Ref Colors For Trace Search", RefColorsForTraceSearch); assert( len(RefColorsForTraceSearch) >=1, "Reference color boxes expected to be 1 or more"); //create an array with one entry for each trace expected. TraceImageList = [trace0, trace0]; //create an array with one entry for each trace expected, of the original .png showTraceOnThisRefImage = [0, 0]; RefImages = [ //X position to place image and trace discovered [2000, "demo_image_in_poly-tiger-trace-outer.png"] ]; ContourTraceListRough = LT_buildTopLineList(TraceImageList, [TTx/2,2],RefColorsForTraceSearch, [0,1], [1,0]); //contour trace lines are XY = [0,0] at lower left! Still in pixel dimensions. //the traces tend to be jaggy. Use nSpline to interpolate, reduce the number of // data points, and generally smooth them out!! ContourTraceList = [ for(i=[0:len(ContourTraceListRough)-1]) nSpline(ContourTraceListRough[i], len(ContourTraceListRough[i])/2.0 ) ] ; //generating the polygon traces can be lengthy. Trace data from LT_buildTopLineList() can be captured into a // log file, and included for subsequent steps. //CAPTURE TRACES in stderr // in Windows cmd.exe: // set oscad="c:\Program Files\OpenSCAD\openscad.com" // cd directory of .scad // %oscad% -o test.png test.scad > test.txt 2>&1 // --> performs Preview //echo("Traces", ContourTraceList); if (1) { //confirm trace lines are correct by showing on top of their image for (i = [0: len(ContourTraceList)-1] ) { traceLen = len(ContourTraceList[i]); echo("show trace", i, "of length", traceLen); if(traceLen < 5) echo("ERROR: this trace is too short to process"); translate([RefImages[showTraceOnThisRefImage[i]][0], 0, 0]) { union () { color(c=RefColorsForTraceSearch[i]/255.0) ShowLinePoints(ContourTraceList[i], 5.0); if (traceLen > 1) color(c=RefColorsForTraceSearch[i]/255.0) translate([ ContourTraceList[i][0][0], ContourTraceList[i][0][1]+5, 0]) sphere(r=4); } } } translate([0,0,-10]) for (imgN = [0:len(RefImages)-1]) { imageFile = RefImages[imgN][1]; translate([RefImages[imgN][0],0,-10]) scale([1.0,1.0, 6.0/255]) surface(file=imageFile, convexity=3); } } //Don't go further until the above trace lines are properly showing on top of their images! //a rectangle is defined, to which the image file is aligned. // Normally this rectangle has the same aspect ratio as the image, and is // fine to set to match the pixel dimensions of the image. // The rectangle can be placed anywhere in the Openscad positive XY coordinate system, // however the cutting polygon XY values, which are pixel indexes from the trace image, // must be within the rectangle!! // Think of this rectangle as stretching the image over the trace. //In order to keep the trace aligned with the image to show, typically the // file supplying ImageToCut is the same viewing area as the polygon trace file. // This image.png file can be of reduced pixel dimensions during development, and // use a full resolution image in the final pass. These pixel dimensions need not // match the trace image file, however the viewing areas must align! // This image .png file must be processed with // python3 png-reader.py demo_image_in_poly_tiger_640x360.png > demo_image_tiger.txt // python3 png-reader.py demo_image_in_poly_tiger_300x169.png > demo_image_tiger_sm.txt include <./demo_image_tiger.txt>; ImageToCut = demo_image_in_poly_tiger_640x360png; //include <./demo_image_tiger_sm.txt>; ImageToCut = demo_image_in_poly_tiger_300x169png; //rectangle surrounding the trace polygon, to define image positioning. // Best is to stay with trace image pixel dimenions to insure the trace is // within this box. // This permits changing the ImageToCut image file pixel dimensions to be smaller // during development. // Xmin = 0; Xmax_osu = len(trace0[0])-1; //rectangle matching the trace data. Ymin = 0; Ymax_osu = len(trace0)-1 ; ImgPixHeight = 3.0; //depending upon the image contrast and brightness, adjusting //this from 1.0 to 5.0 can make the image appear better. BackingThickness = 5.0; //the image is shown on the -y side of the polyhedron, which stands in the XZ positive plane. // Image rests on y=0. Backing is in +y. // Then we rotate it to XY with image in +z rotate([-90,0,0]) LT_ImageInsidePoly(ImageToCut, ContourTraceList[0], Xmin, Xmax_osu, Ymax_osu, Ymin, false, ImgPixHeight, BackingThickness, true, true); //show image in the circle trace translate([1000,0,0]) rotate([-90,0,0]) LT_ImageInsidePoly(ImageToCut, ContourTraceList[1], Xmin, Xmax_osu, Ymax_osu, Ymin, false, ImgPixHeight, BackingThickness, true, true);