32float DistToLine(
int x0,
int y0,
int x1,
int y1,
int x2,
int y2){
33 return abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1))/
sqrt((
float)((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
36TomoObject::TomoObject(vector<Vec3i> allpt,
float md,
int slice){
40 for (
int i=0; i<(int)allpt.size(); i++){
49 for (
int i=0; i<(int)allpt.size()-1; i++){
53 for (
int j=0; j<(int)allpt.size(); j++){
55 float dst=(allpt[j][0]-nowp[0])*(allpt[j][0]-nowp[0])+(allpt[j][1]-nowp[1])*(allpt[j][1]-nowp[1]);
80 ptid.push_back(newpt);
96 for (
int i=1; i<(int)
ptid.size(); i++){
99 for (
int j=
ptid[i-1]; j<
ptid[i]; j++){
113 fprintf(fp,
"color 0 1 0 0\nopen\ncontour 0 0 %d\n",(
int)
ptid.size());
114 for (
int i=0; i<(int)
ptid.size(); i++){
120 return (
int)
ptid.size();
126 segid.push_back(myid);
147 printf(
"No map input.\n");
153 rank->process_inplace(
"morph.object.density",
Dict(
"thresh",0,
"more_neighbor",
true));
154 int nx=rank->get_xsize();
155 int ny=rank->get_ysize();
158 for (
int i=0; i<numo; i++){
159 float max=rank->get_attr(
"maximum");
165 for (
int x=0;
x<nx;
x++){
166 for (
int y=0;
y<ny;
y++){
167 if (rank->get_value_at(
x,
y)==max){
172 if (nb>2) branch=
true;
174 rank->set_value_at_fast(
x,
y,0);
179 if(
verb) printf(
"id=%d, size=%d",
int(curid),
int(pts.size()));
181 if (
verb) printf(
"\n\thave branch, throw out.\n");
185 if (
verb) printf(
" \t%d points\n",
objs.back().get_size() );
195 FILE *fp = fopen(file,
"w");
199 fprintf(fp,
"imod %d\n",(
int)
objs.size());
200 fprintf(fp,
"max %d %d %d\n",nx,ny,nz);
201 for (
int i=0; i<(int)
objs.size(); i++){
202 fprintf(fp,
"object %d 1 0\n",i);
203 objs[i].write_imod(fp);
211 for (
int i=-1; i<=1; i++){
212 for (
int j=-1; j<=1; j++){
213 nb+= (
skelmap->get_value_at(
x+i,
y+j)>0 ? 1 : 0);
Dict is a dictionary to store <string, EMObject> pair.
EMData stores an image's data and defines core image processing routines.
void enlong(EMData *bwmap, EMData *skelmap)
void write_imod(FILE *fp)
vector< Vec3i > allpoints
int check_neighbors(int x, int y)
int generate_objects(int numo, float maxdist, int nowslice)
void write_imod(const char *file)
int read_skelmap(EMData *map)
vector< TomoObject > objs
EMData * sqrt() const
return square root of current image
float DistToLine(int x0, int y0, int x1, int y1, int x2, int y2)