Created
September 2, 2011 00:54
-
-
Save jarvist/1187699 to your computer and use it in GitHub Desktop.
Builds against Survex 1.0.39 to convert .3d cave survey files --> CGO Pymol graphics objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 3d2text.c | |
* | |
* changes .3d files to ascii text | |
* | |
* Copyright (C) 2001, Clewin Griffith. | |
* Pymol CGO output additions (C) 2011, Jarvist Moore Frost. | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*/ | |
// Compiles against an already 'configure && make' version of Survex 1.0.39 with: | |
// gcc -o 3d2text_colour 3d2text_colour.c img.o useful.o message.o filename.o osdepend.o cmdline.o -lm | |
// in working directory: survex-1.0.39/src | |
#ifdef HAVE_CONFIG_H | |
# include <config.h> | |
#endif | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <float.h> | |
#include <limits.h> | |
#include <math.h> | |
#include "img.h" /*survex .3d file loading functions */ | |
const char *survey = NULL; | |
//original of this function from here: | |
// http://www.nunosantos.net/archives/114 | |
// Assume public domain? | |
void HSVtoRGB( int *r, int *g,int *b, int h, int s, int v ) | |
{ | |
int f; | |
long p, q, t; | |
if( s == 0 ) | |
{ | |
*r = *g = *b = v; | |
return; | |
} | |
f = ((h%60)*255)/60; | |
h /= 60; | |
p = (v * (256 - s))/256; | |
q = (v * ( 256 - (s * f)/256 ))/256; | |
t = (v * ( 256 - (s * ( 256 - f ))/256))/256; | |
switch( h ) { | |
case 0: | |
*r = v; | |
*g = t; | |
*b = p; | |
break; | |
case 1: | |
*r = q; | |
*g = v; | |
*b = p; | |
break; | |
case 2: | |
*r = p; | |
*g = v; | |
*b = t; | |
break; | |
case 3: | |
*r = p; | |
*g = q; | |
*b = v; | |
break; | |
case 4: | |
*r = t; | |
*g = p; | |
*b = v; | |
break; | |
default: | |
*r = v; | |
*g = p; | |
*b = q; | |
break; | |
} | |
} | |
void Load3dFile(const char* filename) | |
{ | |
img* pimg; | |
pimg =img_open_survey(filename, survey); | |
int r,g,b,h,s,v; | |
while(1) | |
{ | |
img_point pt; | |
float x,y,z,ox,oy,oz; | |
int result = img_read_item(pimg, &pt); | |
x=pt.x; | |
y=pt.y; | |
z=pt.z; | |
if(result==img_STOP) break; | |
// if(result==img_MOVE ) | |
// printf("VERTEX, %d, %d, %d,\n", x, y, z); | |
if (result==img_LINE) | |
{ | |
s=80; | |
v=256; | |
h=(360*(2000-z)/1000.0); // hard coded as I know nothing's > 2000m high. Well, other than Kuk... | |
HSVtoRGB(&r,&g,&b,h,s,v); | |
if (x==floor(x) && y==floor(y)) //i.e. DEM data. Filthy, I know. | |
printf("LINEWIDTH, 1.0, \nCOLOR, 1.0, 1.0, 1.0,\n"); | |
else | |
{ | |
printf("COLOR, %f, %f, %f,\n",r/255.0,g/255.0,b/255.0); | |
//approx cave passage linewidth based on survey shot length | |
printf("LINEWIDTH, %f,\n",0.2*(sqrt((ox-x)*(ox-x) + (oy-y)*(oy-y) + (oz-z)*(oz-z)))); | |
} | |
printf("VERTEX, %f, %f, %f,\nVERTEX, %f, %f, %f,\n", ox,oy,oz,x, y, z); | |
} | |
ox=x; oy=y; oz=z; | |
} | |
// printf("-1 %d %d %d\n", cminx, cminy, cminz); | |
// printf("-1 %d %d %d\n", cmaxx, cmaxy, cmaxz); | |
} | |
int main( int argc, char* argv[] ) | |
{ | |
const char *survey = NULL; | |
if(argv[1]) Load3dFile(argv[1]); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Heads + tails the output from the CGO renderer '3d2text_colour.c' for opening with pymol | |
#gcc -o 3d2text_colour 3d2text_colour.c img.o useful.o message.o filename.o osdepend.o cmdline.o -lm | |
#run this magic new program on a 1.0.39 version .3d file, and direct the result into a file... | |
#./3d2text_colour ../../mig_stable.3d > ../../mid_colour.txt | |
#top and tail these CGO commands with a header so Pymol renders correctly... | |
#./build_cgo.sh mid_colour.txt > mig_cgo_colour.py | |
#pymol mig_cgo_colour.py | |
#compiles a movie out of the PNGs output from pymol movie creator (command 'mpng') | |
#mencoder mf://*.png -o test.avi -ovc lavc | |
cat << EOF | |
from pymol.cgo import * # get constants | |
from pymol import cmd | |
obj = [ | |
BEGIN, LINES, | |
COLOR, 1.0, 1.0, 1.0, | |
EOF | |
cat $1 | |
#NB: Axes origin hard coded to Tominski Migovec location; comment out / change for your own data | |
cat << EOF | |
END | |
] | |
w = 12 # cylinder width | |
l = 150 # cylinder length | |
h = 50 # cone hight | |
d = w * 1.618 # cone base diameter | |
x=405000.0 | |
y=123963.0 | |
z=800.0 | |
axes = [CYLINDER, x, y, z, x+l, y, z, w, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, | |
CYLINDER, x, y, z, x, y+l, z, w, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, | |
CYLINDER, x, y, z, x, y, z+l, w, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, | |
CONE, x+l, y, z, x+h+l, y, z, d, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, | |
CONE, x, y+ l, z, x, y+h+l, z, d, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, | |
CONE, x, y, z+l, x, y, z+h+l, d, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0] | |
cmd.load_cgo(axes,'axes') | |
cmd.load_cgo(obj,'cgo01') | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment