/* ****************************************************************** */ void WritePPM (double ***Vdbl, char *var_name, char *filename, Grid *grid) /* * * * * ******************************************************************** */ { int ic, ir; FILE *fl; char header[512]; Image *ppm; ppm = GetImage (var_name); SetColorMap (ppm->r, ppm->g, ppm->b, ppm->colormap); GetSlice (Vdbl, ppm, grid); if (prank != 0) return; sprintf (header,"P6\n%d %d\n255\n", ppm->ncol, ppm->nrow); fl = fopen (filename,"w"); fprintf(fl,"%s",header); for (ir = 0; ir < ppm->nrow; ir++){ fwrite (ppm->rgb[ir], sizeof(RGB), ppm->ncol, fl); } fclose(fl); }
void CPlayer::Increase() { if (!m_pHead) { m_pHead = new CSphereEntity(m_pReflectObject, GetHeadRadius(), GetSlice(), GetSlice()); CSphereEntity *pBody = new CSphereEntity(m_pColorLightObject, GetBodyRadius(), GetSlice(), GetSlice()); pBody->Create(); m_listBody.push_back(pBody); m_pTail = new CSphereEntity(m_pColorLightObject, GetBodyRadius(), GetSlice(), GetSlice()); m_pTail->Create(); ISceneNode *pRootNode = SCENEMGR->GetCurrentScene()->GetRootNode(); pRootNode->AddChild(pBody); pRootNode->AddChild(m_pTail); InitPosition(); } else { CSphereEntity *body = new CSphereEntity(m_pColorLightObject, GetBodyRadius(), GetSlice(), GetSlice()); body->Create(); CVector3 vBackBody = m_listBody.back()->GetPosition(); CVector3 vSrcTail = m_pTail->GetPosition(); body->SetPosition(vSrcTail); m_listBody.push_back(body); m_pTail->SetPosition(vBackBody + 1.5f * (vSrcTail - vBackBody)); ISceneNode *pRootNode = SCENEMGR->GetCurrentScene()->GetRootNode(); pRootNode->AddChild(body); } }
/* ****************************************************************** */ void WritePNG (double ***Vdbl, char *var_name, char *filename, Grid *grid) /* * * * * ******************************************************************** */ { int ic, ir, i; png_structp png_ptr; png_infop info_ptr; int backgroundcolour_; int bit_depth_; int colortype_; int compressionlevel_; int indx; double filegamma_; Image *png; unsigned char **image; FILE *fp; png = GetImage (var_name); SetColorMap (png->r, png->g, png->b, png->colormap); GetSlice (Vdbl, png, grid); if (prank != 0) return; image = (png_bytepp)malloc(png->nrow*sizeof(png_bytep)); for (ir = 0; ir < png->nrow; ir++) { image[ir] = (png_bytep)malloc(6*png->ncol*sizeof(png_byte)); } for(ic = 0; ic < png->ncol; ic++){ for(ir = 0; ir < png->nrow; ir++){ i = 6*ic; image[ir][i] = png->rgb[ir][ic].r; /* -- red -- */ image[ir][i+1] = 0; image[ir][i+2] = png->rgb[ir][ic].g; /* -- green -- */ image[ir][i+3] = 0; image[ir][i+4] = png->rgb[ir][ic].b; /* -- blue -- */ image[ir][i+5] = 0; }} /* -- write --- */ compressionlevel_ = 6; backgroundcolour_ = 0; bit_depth_ = 16; filegamma_ = 0.; colortype_ = 2.; fp = fopen(filename, "wb"); if(fp == NULL){ printf(" ! error opening file in writing data\n"); exit(1); } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); info_ptr = png_create_info_struct(png_ptr); png_init_io(png_ptr, fp); /* if(compressionlevel_ != -2){ */ png_set_compression_level(png_ptr, compressionlevel_); /* } else { png_set_compression_level(png_ptr, PNGWRITER_DEFAULT_COMPRESSION); }*/ png_set_IHDR(png_ptr, info_ptr, png->ncol, png->nrow, bit_depth_, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); if(filegamma_ < 1.0e-1){ filegamma_ = 0.7; } png_set_gAMA(png_ptr, info_ptr, filegamma_); /* time_t gmt; png_time mod_time; png_text text_ptr[5]; time(&gmt); png_convert_from_time_t(&mod_time, gmt); png_set_tIME(png_ptr, info_ptr, &mod_time); */ png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, image); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); free((char *) image[0]); free((char *) image); }
amyCubeLing::ItrType amyCubeLing::ComputeIteratorFromView() { amyCube::tCube ::SizeType size = m_InputRegion.GetSize(); amyCube::tCube::IndexType index= m_InputRegion.GetIndex(); amyCube::tCube::RegionType region; if(this->GetInputView()==amyUtil::AXIAL) { if(this->GetView()==amyUtil::AXIAL) { size[2]=1; index[2]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(0); itr.SetSecondDirection(1); return itr; } if(this->GetView()==amyUtil::CORONAL) { size[1]=1; index[1]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(0); itr.SetSecondDirection(2); return itr; } if(this->GetView()==amyUtil::SAGITTAL) { size[0]=1; index[0]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(1); itr.SetSecondDirection(2); return itr; } } if(this->GetInputView()==amyUtil::CORONAL) { if(this->GetView()==amyUtil::AXIAL) { size[1]=1; index[1]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(0); itr.SetSecondDirection(2); return itr; } if(this->GetView()==amyUtil::CORONAL) { size[2]=1; index[2]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(0); itr.SetSecondDirection(1); return itr; } if(this->GetView()==amyUtil::SAGITTAL) { size[0]=1; index[0]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(2); itr.SetSecondDirection(1); return itr; } } if(this->GetInputView()==amyUtil::SAGITTAL) { if(this->GetView()==amyUtil::AXIAL) { size[1]=1; index[1]=GetSlice(); region.SetSize(size); region.SetIndex(index); amyCube::tCube::Pointer p=this->GetInput()->obj; ItrType itr(p,region); itr.SetFirstDirection(2); itr.SetSecondDirection(0); return itr; } if(this->GetView()==amyUtil::CORONAL) { size[0]=1; index[0]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(2); itr.SetSecondDirection(1); return itr; } if(this->GetView()==amyUtil::SAGITTAL) { size[2]=1; index[2]=GetSlice(); region.SetSize(size); region.SetIndex(index); ItrType itr(this->GetInput()->obj,region); itr.SetFirstDirection(0); itr.SetSecondDirection(1); return itr; } } }
bool AlignmentMarks::Process() { int maskwidth=10; int top,bottom; int x1,x2,x3,x4,y1,y2; top=FindTop(); if(top==-1) return false; bottom=FindBottom(); if(bottom==-1) return false; if(printIntermediate){ cout << "top=" << top<<" bottom="<< bottom << endl; } int *slice=GetVerticalSlice(0,Width(),maskwidth); EdgeDetect(slice,Height()+1,maskwidth,y1,y2); y2--; if(y1 <= y2){ top=y1;bottom=y2;} if(printIntermediate){ cout << "y1=" << y1<<" y2="<< y2 << endl; } int limit=top + (int)(0.1*(bottom-top)); int h=limit-top+1; slice=GetSlice(top,h,maskwidth); //if(Verbose()>1){ // cout << "Top slice:" << endl; // for(int i=0;i<Width()+2*maskwidth;i++) cout <<i<<": " << (int)slice[i] << endl; //} EdgeDetect(slice,Width()+1,maskwidth,x1,x2); x2--; delete[] slice; limit=bottom-(int)(0.1*(bottom-top)); h=bottom-limit+1; slice=GetSlice(limit,h,maskwidth); //if(Verbose()>1){ // cout << "Bottom slice:" << endl; // for(int i=0;i<Width()+2*maskwidth;i++) cout <<i<<": " << (int)slice[i] << endl; //} EdgeDetect(slice,Width()+1,maskwidth,x3,x4); x4--; delete[] slice; if(printIntermediate){ cout <<"x1=" << x1<<" x2="<< x2 << endl; cout << "x3=" << x3<<" x4="<< x4 << endl; } // scale the bottom alignment line double top_factor = 0.87; double center=(x3+x4)/2.0; double half_len = (x4-x3)*top_factor/2.0; x3 = (int)(center-half_len); x4 = (int)(center+half_len); if(printIntermediate){ cout << "After scaling x3=" << x3<<" x4="<< x4 << endl; } // now write the result SegmentationResult result; ostringstream *str=new ostringstream; (*str) << x1 << " " << top << " " << x2 << " " << top; result.name = "alignment_marks_top"; result.type = "line"; result.value = str->str(); getImg()->writeFrameResultToXML(this,result); delete str; str=new ostringstream; (*str) << x3 << " " << bottom << " " << x4 << " " << bottom; result.name = "alignment_marks_bottom"; result.value = str->str(); getImg()->writeFrameResultToXML(this,result); delete str; return true; }