void Mirror(TreeNode *pRoot) { if(!pRoot) return; SwapVal(pRoot); Mirror(pRoot->left); Mirror(pRoot->right); }
void imProcessMirror(const imImage* src_image, imImage* dst_image) { int i; int src_depth = src_image->has_alpha? src_image->depth+1: src_image->depth; for (i = 0; i < src_depth; i++) { switch(src_image->data_type) { case IM_BYTE: Mirror(src_image->width, src_image->height, (imbyte*)src_image->data[i], dst_image->width, dst_image->height, (imbyte*)dst_image->data[i]); break; case IM_USHORT: Mirror(src_image->width, src_image->height, (imushort*)src_image->data[i], dst_image->width, dst_image->height, (imushort*)dst_image->data[i]); break; case IM_INT: Mirror(src_image->width, src_image->height, (int*)src_image->data[i], dst_image->width, dst_image->height, (int*)dst_image->data[i]); break; case IM_FLOAT: Mirror(src_image->width, src_image->height, (float*)src_image->data[i], dst_image->width, dst_image->height, (float*)dst_image->data[i]); break; case IM_CFLOAT: Mirror(src_image->width, src_image->height, (imcfloat*)src_image->data[i], dst_image->width, dst_image->height, (imcfloat*)dst_image->data[i]); break; } } }
void Mirror(TreeNode *pRoot) { if (pRoot == NULL) return; swap(pRoot->left, pRoot->right); Mirror(pRoot->left); Mirror(pRoot->right); }
void Mirror(TreeNode *pRoot) { if (pRoot == NULL) return; TreeNode *tmp = pRoot->left; pRoot->left = pRoot->right; pRoot->right = tmp; Mirror(pRoot->left); Mirror(pRoot->right); }
/// 求二叉树的镜像 /// 递归解法:如果二叉树为空,返回空 /// 如果二叉树不为空,求左子树和右子树的镜像,然后交换左子树和右子树 TreeNode* Mirror(TreeNode* root) { if(root == NULL) return NULL; TreeNode* pLeft = Mirror(root->left); TreeNode* pRight = Mirror(root->right); root->left = pRight; root->right = pLeft; return root; }
void DIMENSION::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); // DIMENSION items are not usually on copper layers, so // copper layers count is not taken in accoun in Flip transform SetLayer( FlipLayer( GetLayer() ) ); }
bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) { GetLogger()->Info("Loading model '%s'\n", fileName.c_str()); CModelFile modelFile; std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) { GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str()); return false; } ModelInfo modelInfo; modelInfo.baseObjRank = m_engine->CreateBaseObject(); modelInfo.triangles = modelFile.GetTriangles(); if (mirrored) Mirror(modelInfo.triangles); FileInfo fileInfo(fileName, mirrored); m_models[fileInfo] = modelInfo; std::vector<VertexTex2> vs(3, VertexTex2()); for (int i = 0; i < static_cast<int>( modelInfo.triangles.size() ); i++) { int state = modelInfo.triangles[i].state; std::string tex2Name = modelInfo.triangles[i].tex2Name; if (modelInfo.triangles[i].variableTex2) { int texNum = m_engine->GetSecondTexture(); if (texNum >= 1 && texNum <= 10) state |= ENG_RSTATE_DUAL_BLACK; if (texNum >= 11 && texNum <= 20) state |= ENG_RSTATE_DUAL_WHITE; char name[20] = { 0 }; sprintf(name, "dirty%.2d.png", texNum); tex2Name = name; } vs[0] = modelInfo.triangles[i].p1; vs[1] = modelInfo.triangles[i].p2; vs[2] = modelInfo.triangles[i].p3; m_engine->AddBaseObjTriangles(modelInfo.baseObjRank, vs, ENG_TRIANGLE_TYPE_TRIANGLES, modelInfo.triangles[i].material, state, modelInfo.triangles[i].tex1Name, tex2Name, modelInfo.triangles[i].lodLevel, false); } return true; }
void Envelope::testMe() { double t0=0, t1=0; SetInterpolateDB(false); Mirror(false); Flatten(0.5); checkResult( 1, Integral(0.0,100.0), 50); checkResult( 2, Integral(-10.0,10.0), 10); Flatten(0.5); checkResult( 3, Integral(0.0,100.0), 50); checkResult( 4, Integral(-10.0,10.0), 10); checkResult( 5, Integral(-20.0,-10.0), 5); Flatten(0.5); Insert( 5.0, 0.5 ); checkResult( 6, Integral(0.0,100.0), 50); checkResult( 7, Integral(-10.0,10.0), 10); Flatten(0.0); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; double result = Integral(0.0,t1); double resulta = Integral(0.0,t0); double resultb = Integral(t0,t1); // Integrals should be additive checkResult( 8, result - resulta - resultb, 0); Flatten(0.0); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; checkResult( 9, Integral(0.0,t1), 5); checkResult( 10, Integral(0.0,t0), 4.999); checkResult( 11, Integral(t0,t1), .001); WX_CLEAR_ARRAY(mEnv); Insert( 0.0, 0.0 ); Insert( 5.0, 1.0 ); Insert( 10.0, 0.0 ); checkResult( 12, NumberOfPointsAfter( -1 ), 3 ); checkResult( 13, NumberOfPointsAfter( 0 ), 2 ); checkResult( 14, NumberOfPointsAfter( 1 ), 2 ); checkResult( 15, NumberOfPointsAfter( 5 ), 1 ); checkResult( 16, NumberOfPointsAfter( 7 ), 1 ); checkResult( 17, NumberOfPointsAfter( 10 ), 0 ); checkResult( 18, NextPointAfter( 0 ), 5 ); checkResult( 19, NextPointAfter( 5 ), 10 ); }
void VisitSection(const IniFile& iniFile, const std::string& sectionName) { if( !utils::startsWith( sectionName, "Mirror ") ) { return; // ignore non-Mirror sections } push_back( Mirror( sectionName.substr(7), // displayname iniFile.GetValue( sectionName, "url" ), utils::toFloat( iniFile.GetValue(sectionName, "weight") )) ); }
void SCH_TEXT::MirrorX( int aXaxis_position ) { // Text is NOT really mirrored; it is moved to a suitable vertical position switch( GetLabelSpinStyle() ) { default: case 0: break; // horizontal text case 1: SetLabelSpinStyle( 3 ); break; // Vert Orientation UP case 2: break; // invert horizontal text case 3: SetLabelSpinStyle( 1 ); break; // Vert Orientation BOTTOM } SetTextY( Mirror( GetTextPos().y, aXaxis_position ) ); }
void SCH_TEXT::MirrorY( int aYaxis_position ) { // Text is NOT really mirrored; it is moved to a suitable horizontal position switch( GetLabelSpinStyle() ) { default: case 0: SetLabelSpinStyle( 2 ); break; // horizontal text case 1: break; // Vert Orientation UP case 2: SetLabelSpinStyle( 0 ); break; // invert horizontal text case 3: break; // Vert Orientation BOTTOM } SetTextX( Mirror( GetTextPos().x, aYaxis_position ) ); }
void CDimageView::OnVmirror() { // TODO: 在此添加命令处理程序代码 CDimageDoc* pDoc= GetDocument(); if(!pDoc->m_Img->IsValidate()) //Img为NULL则无法操作 return; if(pDoc->m_OImg->IsValidate()) //每回先更新OImg内容,有改变即全删重新分配地址,比较保守 { delete []pDoc->m_OImg; pDoc->m_OImg=NULL; } pDoc->m_OImg= new CImg(*pDoc->m_Img); delete []pDoc->m_Img; pDoc->m_Img = Mirror(pDoc->m_OImg,1); Invalidate(1); }
XnStatus XnDeviceStream::Read(XnStreamData* pStreamOutput) { XnStatus nRetVal = XN_STATUS_OK; // check the size of the stream output object nRetVal = XnStreamDataCheckSize(pStreamOutput, GetRequiredDataSize()); XN_IS_STATUS_OK(nRetVal); // first mark old data as old pStreamOutput->bIsNew = FALSE; // now check if we have some new data if (m_bNewDataAvailable) { // copy data nRetVal = ReadImpl(pStreamOutput); XN_IS_STATUS_OK(nRetVal); xnOSEnterCriticalSection(&m_hCriticalSection); XnBool bMirror = IsMirrored(); xnOSLeaveCriticalSection(&m_hCriticalSection); // mirror it if needed if (bMirror) { nRetVal = Mirror(pStreamOutput); XN_IS_STATUS_OK(nRetVal); } // mark that data is new pStreamOutput->bIsNew = TRUE; // and that we don't have new info m_bNewDataAvailable = FALSE; } return (XN_STATUS_OK); }
BOOL CBCGPControlRenderer::Create (const CBCGPControlRendererParams& params, BOOL bFlipvert /*= FALSE*/) { CleanUp (); m_Params = params; LPCTSTR lpszResID = m_Params.GetResourceID (); if (lpszResID != NULL) { m_Bitmap.SetImageSize (m_Params.m_rectImage.Size ()); m_Bitmap.SetPreMultiplyAutoCheck (m_Params.m_bPreMultiplyCheck); m_Bitmap.SetMapTo3DColors (FALSE); m_Bitmap.LoadStr (lpszResID); if (bFlipvert) { m_Bitmap.MirrorVert (); } if (m_Params.m_clrTransparent != CLR_DEFAULT) { m_Bitmap.SetTransparentColor (m_Params.m_clrTransparent); } if (m_Params.m_clrBase != (COLORREF)-1 && m_Params.m_clrTarget != (COLORREF)-1) { m_Bitmap.AddaptColors (m_Params.m_clrBase, m_Params.m_clrTarget); } if (CBCGPToolBarImages::IsRTL () && m_Bitmap.GetImageWell () != NULL && m_Params.m_clrTransparent == CLR_DEFAULT) { BITMAP bmp; if (::GetObject (m_Bitmap.GetImageWell (), sizeof (BITMAP), &bmp) != 0) { if (bmp.bmBitsPixel == 32) { Mirror (); } } } if (m_Params.m_rectSides.IsRectNull ()) { m_Params.m_rectSides = m_Params.m_rectCorners; } if (m_Params.m_rectInter.IsRectNull ()) { m_Params.m_rectInter = CRect (CPoint (0, 0), m_Params.m_rectImage.Size ()); m_Params.m_rectInter.left += m_Params.m_rectCorners.left; m_Params.m_rectInter.top += m_Params.m_rectCorners.top; m_Params.m_rectInter.right -= m_Params.m_rectCorners.right; m_Params.m_rectInter.bottom -= m_Params.m_rectCorners.bottom; } if (bFlipvert) { long temp; temp = m_Params.m_rectCorners.top; m_Params.m_rectCorners.top = m_Params.m_rectCorners.bottom; m_Params.m_rectCorners.bottom = temp; temp = m_Params.m_rectSides.top; m_Params.m_rectSides.top = m_Params.m_rectSides.bottom; m_Params.m_rectSides.bottom = temp; long height = m_Params.m_rectImage.Height (); temp = m_Params.m_rectInter.top; m_Params.m_rectInter.top = height - m_Params.m_rectInter.bottom; m_Params.m_rectInter.bottom = height - temp; } } return TRUE; }
//********************************************************************************* BOOL CBCGPShadowRenderer::Create (int nDepth, COLORREF clrBase, int iMinBrightness/* = 0*/, int iMaxBrightness/* = 100*/, BOOL bCanMirror/* = TRUE*/) { if (IsValid() && m_nDepth == nDepth && m_clrBase == clrBase && m_iMinBrightness == iMinBrightness && m_iMaxBrightness == iMaxBrightness) { return TRUE; } CleanUp (); if (nDepth == 0 || iMaxBrightness == 0) { return FALSE; } m_nDepth = nDepth; m_clrBase = clrBase; m_iMinBrightness = iMinBrightness; m_iMaxBrightness = iMaxBrightness; if (m_clrBase == (COLORREF)-1) { clrBase = globalData.clrBarFace; } HBITMAP hBitmap = CBCGPDrawManager::PrepareShadowMask (nDepth, clrBase, iMinBrightness, iMaxBrightness); if (hBitmap == NULL) { return FALSE; } int nSize = nDepth < 3 ? 3 : nDepth; int nDestSize = nSize * 2 + 1; m_Params.m_rectImage = CRect (0, 0, nDestSize, nDestSize); m_Params.m_rectCorners = CRect (nSize, nSize, nSize, nSize); m_Params.m_rectSides = m_Params.m_rectCorners; m_Params.m_rectInter = CRect (CPoint (0, 0), m_Params.m_rectImage.Size ()); m_Params.m_rectInter.left += m_Params.m_rectCorners.left; m_Params.m_rectInter.top += m_Params.m_rectCorners.top; m_Params.m_rectInter.right -= m_Params.m_rectCorners.right; m_Params.m_rectInter.bottom -= m_Params.m_rectCorners.bottom; m_Bitmap.SetImageSize (m_Params.m_rectImage.Size ()); m_Bitmap.SetPreMultiplyAutoCheck (m_Params.m_bPreMultiplyCheck); m_Bitmap.SetMapTo3DColors (FALSE); m_Bitmap.AddImage (hBitmap, TRUE); ::DeleteObject (hBitmap); if (bCanMirror && CBCGPToolBarImages::IsRTL () && m_Bitmap.GetImageWell () != NULL) { Mirror (); } return m_Bitmap.GetCount () == 1; }
void MasukProgram() { int a; float b,c; int d,e; scanf("%d",&a); switch (a) { case 1 : { BacaPOINT(&P1); break; } case 2 : { BacaPOINT(&P2); break; } case 3 : { TulisPOINT(P1); break; } case 4 : { TulisPOINT(P2); break; } case 5 : { TulisPOINT(plus(P1,P2)); break; } case 6 : { TulisPOINT(minus(P1,P2)); break; } case 7 : { printf("%.2f\n",dot(P1,P2)); break; } case 8 : { printf("%.2f\n",cross(P1,P2)); break; } case 9 : { if (IsOrigin(P1)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 10 : { if (IsOnSbX(P1)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 11 : { if (IsOnSbY(P1)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 12 : { if (EQ(P1,P2)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 13 : { if (NEQ(P1,P2)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 14 : { if (lebihkecil(P1,P2)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 15 : { if (lebihbesar(P1,P2)) { printf("Ya\n"); } else { printf("Tidak\n"); } break; } case 16 : { printf("Titik berada di kuadran %d\n",Kuadran(P1)); break; } case 17 : { TulisPOINT(NextX(P1)); break; } case 18 : { TulisPOINT(NextY(P1)); break; } case 19 : { scanf("%f %f",&b,&c); TulisPOINT(PlusDelta(P1,b,c)); break; } case 20 : { scanf("%d %d",&d,&e); TulisPOINT(MirrorOf(P1,d,e)); break; } case 21 : { printf("Jarak dari (0,0) adalah %.2f\n",Jarak0(P1)); break; } case 22 : { printf("Panjang P1 ke P2 adalah %.2f\n",Panjang(P1,P2)); break; } case 23 : { scanf("%f %f",&b,&c); Geser(&P1,b,c); break; } case 24 : { GeserKeSbX(&P1); break; } case 25 : { GeserKeSbY(&P1); break; } case 26 : { scanf("%d %d",&d,&e); Mirror(&P1,d,e); break; } case 27 : { scanf("%f",&b); Putar(&P1,b); break; } case 28 : { scanf("%d",&b); SetAbsis(P1,b); break; } case 29 : { scanf("%d",&b); SetOrdinat(P1,b); break; } case 30 : { keluar = true; break; } } }
void ZONE_CONTAINER::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); SetLayer( FlipLayer( GetLayer() ) ); }
int main(){ int i,h,DX,DY; float sudut; POINT ptest,p1,p2; srand(time(NULL)); ptest=MakePOINT(rand(),rand()); TulisPOINT(ptest); SetAbsis(&ptest,rand()); TulisPOINT(ptest); SetOrdinat(&ptest,rand()); TulisPOINT(ptest); BacaPOINT(&ptest); TulisPOINT(ptest); //cek operator relasional printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); p2=MakePOINT(rand(),rand()); TulisPOINT(p1); printf("=="); TulisPOINT(p2); printf("="); h=EQ(p1,p2); printf("%x\n",h); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); p2=p1; TulisPOINT(p1); printf("=="); TulisPOINT(p2); printf("="); h=EQ(p1,p2); printf("%x\n",h); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); p2=MakePOINT(rand(),rand()); TulisPOINT(p1); printf("!="); TulisPOINT(p2); printf("="); h=NEQ(p1,p2); printf("%x\n",h); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); p2=p1; TulisPOINT(p1); printf("!="); TulisPOINT(p2); printf("="); h=NEQ(p1,p2); printf("%x\n",h); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); TulisPOINT(p1); printf("is Origin"); printf("="); h=IsOrigin(p1); printf("%x\n",h); } p1=MakePOINT(0,0); TulisPOINT(p1); printf("is Origin"); printf("="); h=IsOrigin(p1); printf("%x\n",h); printf("\n\ncek\n"); p1=MakePOINT(0,rand()); TulisPOINT(p1); printf("is Origin"); printf("="); h=IsOrigin(p1); printf("%x\n",h); printf("\n\ncek\n"); p1=MakePOINT(rand(),0); TulisPOINT(p1); printf("is Origin"); printf("="); h=IsOrigin(p1); printf("%x\n",h); printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); TulisPOINT(p1); printf("is On SbX"); printf("="); h=IsOnSbX(p1); printf("%x\n",h); } p1=MakePOINT(0,0); TulisPOINT(p1); printf("is SbX"); printf("="); h=IsOnSbX(p1); printf("%x\n",h); p1=MakePOINT(0,rand()); TulisPOINT(p1); printf("is SbX"); printf("="); h=IsOnSbX(p1); printf("%x\n",h); p1=MakePOINT(rand(),0); TulisPOINT(p1); printf("is SbX"); printf("="); h=IsOnSbX(p1); printf("%x\n",h); printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); TulisPOINT(p1); printf("is On SbY"); printf("="); h=IsOnSbY(p1); printf("%x\n",h); } p1=MakePOINT(0,0); TulisPOINT(p1); printf("is SbY"); printf("="); h=IsOnSbY(p1); printf("%x\n",h); p1=MakePOINT(0,rand()); TulisPOINT(p1); printf("is SbY"); printf("="); h=IsOnSbY(p1); printf("%x\n",h); p1=MakePOINT(rand(),0); TulisPOINT(p1); printf("is SbY"); printf("="); h=IsOnSbY(p1); printf("%x\n",h); printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand()-rand(),rand()-rand()); printf("kuadran "); TulisPOINT(p1); printf("="); h=Kuadran(p1); printf("%d\n",h); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); printf("NextX "); TulisPOINT(p1); printf("="); TulisPOINT(NextX(p1)); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand(),rand()); printf("NextY "); TulisPOINT(p1); printf("="); TulisPOINT(NextY(p1)); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand()-rand(),rand()-rand()); TulisPOINT(p1); DX=rand()%10; DY=rand()%10; printf(" + (%d,%d) =",DX,DY); TulisPOINT(PlusDelta(p1,DX,DY)); printf("\n"); TulisPOINT(p1); printf(" + (%d,%d)g =",DX,DY); Geser(&p1,DX,DY); TulisPOINT(p1); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT(rand()-rand(),rand()-rand()); printf("MirrorOf("); TulisPOINT(p1); printf(",1,0) ="); TulisPOINT(MirrorOf(p1,1,0)); printf("\n"); } for (i=0;i<14;i++){ p1=MakePOINT(rand()-rand(),rand()-rand()); printf("MirrorOf("); TulisPOINT(p1); printf(",0,1) ="); TulisPOINT(MirrorOf(p1,0,1)); printf("\n"); } for (i=0;i<14;i++){ p1=MakePOINT(rand()-rand(),rand()-rand()); printf("MirrorOf("); TulisPOINT(p1); printf(",1,1) ="); TulisPOINT(MirrorOf(p1,1,1)); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); printf("Jarak0("); TulisPOINT(p1); printf(") = %f",Jarak0(p1)); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); p2=MakePOINT((rand()-rand())%10,(rand()-rand())%10); printf("Panjang("); TulisPOINT(p1); printf(","); TulisPOINT(p2); printf(") = %f",Panjang(p1,p2)); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); TulisPOINT(p1); printf("digeser ke Sb-X menjadi "); GeserKeSbX(&p1); TulisPOINT(p1); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); TulisPOINT(p1); printf("digeser ke Sb-Y menjadi "); GeserKeSbY(&p1); TulisPOINT(p1); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); TulisPOINT(p1); printf("dicerminkan dengan Sb-X menjadi "); Mirror(&p1,1,0); TulisPOINT(p1); printf("\n"); } for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); TulisPOINT(p1); printf("dicerminkan dengan Sb-Y menjadi "); Mirror(&p1,0,1); TulisPOINT(p1); printf("\n"); } for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); TulisPOINT(p1); printf("dicerminkan dengan (0,0) menjadi "); Mirror(&p1,1,1); TulisPOINT(p1); printf("\n"); } printf("\n\ncek\n"); for (i=0;i<14;i++){ p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10); sudut=(float) (rand()%360); TulisPOINT(p1); printf("diputar %0.0f derajat menjadi ",sudut); Putar(&p1,sudut); TulisPOINT(p1); printf("\n"); } printf("M_PI=%f\n",M_PI); return 0; }
void ZONE_CONTAINER::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); int copperLayerCount = GetBoard()->GetCopperLayerCount(); SetLayer( FlipLayer( GetLayer(), copperLayerCount ) ); }
bool CxImageTIF::Decode(CxFile * hFile) { //Comment this line if you need more information on errors // TIFFSetErrorHandler(NULL); //<Patrick Hoffmann> //Open file and fill the TIFF structure // m_tif = TIFFOpen(imageFileName,"rb"); TIFF* m_tif = _TIFFOpenEx(hFile, "rb"); uint32 height=0; uint32 width=0; uint16 bitspersample=1; uint16 samplesperpixel=1; uint32 rowsperstrip=(DWORD)-1; uint16 photometric=0; uint16 compression=1; uint16 orientation=ORIENTATION_TOPLEFT; //<vho> uint16 res_unit; //<Trifon> uint32 x, y; float resolution, offset; BOOL isRGB; BYTE *bits; //pointer to source data BYTE *bits2; //pointer to destination data try{ //check if it's a tiff file if (!m_tif) throw "Error encountered while opening TIFF file"; // <Robert Abram> - 12/2002 : get NumFrames directly, instead of looping // info.nNumFrames=0; // while(TIFFSetDirectory(m_tif,(uint16)info.nNumFrames)) info.nNumFrames++; info.nNumFrames = TIFFNumberOfDirectories(m_tif); if (!TIFFSetDirectory(m_tif, (uint16)info.nFrame)) throw "Error: page not present in TIFF file"; //get image info TIFFGetField(m_tif, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(m_tif, TIFFTAG_IMAGELENGTH, &height); TIFFGetField(m_tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); TIFFGetField(m_tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); TIFFGetField(m_tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); TIFFGetField(m_tif, TIFFTAG_PHOTOMETRIC, &photometric); TIFFGetField(m_tif, TIFFTAG_ORIENTATION, &orientation); if (info.nEscape == -1) { // Return output dimensions only head.biWidth = width; head.biHeight = height; throw "output dimensions returned"; } TIFFGetFieldDefaulted(m_tif, TIFFTAG_RESOLUTIONUNIT, &res_unit); if (TIFFGetField(m_tif, TIFFTAG_XRESOLUTION, &resolution)) { if (res_unit == RESUNIT_CENTIMETER) resolution = (float)(resolution*2.54f + 0.5f); SetXDPI((long)resolution); } if (TIFFGetField(m_tif, TIFFTAG_YRESOLUTION, &resolution)) { if (res_unit == RESUNIT_CENTIMETER) resolution = (float)(resolution*2.54f + 0.5f); SetYDPI((long)resolution); } if (TIFFGetField(m_tif, TIFFTAG_XPOSITION, &offset)) info.xOffset = (long)offset; if (TIFFGetField(m_tif, TIFFTAG_YPOSITION, &offset)) info.yOffset = (long)offset; head.biClrUsed=0; info.nBkgndIndex =-1; if (rowsperstrip>height){ rowsperstrip=height; TIFFSetField(m_tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); } isRGB = (bitspersample >= 8) && (photometric == PHOTOMETRIC_RGB) || (photometric == PHOTOMETRIC_YCBCR) || (photometric == PHOTOMETRIC_SEPARATED) || (photometric == PHOTOMETRIC_LOGL) || (photometric == PHOTOMETRIC_LOGLUV); if (isRGB){ head.biBitCount=24; }else{ if ((photometric==PHOTOMETRIC_MINISBLACK)||(photometric==PHOTOMETRIC_MINISWHITE)){ if (bitspersample == 1){ head.biBitCount=1; //B&W image head.biClrUsed =2; } else if (bitspersample == 4) { head.biBitCount=4; //16 colors gray scale head.biClrUsed =16; } else { head.biBitCount=8; //gray scale head.biClrUsed =256; } } else if (bitspersample == 4) { head.biBitCount=4; // 16 colors head.biClrUsed=16; } else { head.biBitCount=8; //256 colors head.biClrUsed=256; } } if (info.nEscape) throw "Cancelled"; // <vho> - cancel decoding Create(width,height,head.biBitCount,CXIMAGE_FORMAT_TIF); //image creation if (!pDib) throw "CxImageTIF can't create image"; #if CXIMAGE_SUPPORT_ALPHA if (samplesperpixel==4) AlphaCreate(); //add alpha support for 32bpp tiffs if (samplesperpixel==2 && bitspersample==8) AlphaCreate(); //add alpha support for 8bpp + alpha #endif //CXIMAGE_SUPPORT_ALPHA TIFFGetField(m_tif, TIFFTAG_COMPRESSION, &compression); SetCodecOption(compression); // <DPR> save original compression type if (isRGB) { // Read the whole image into one big RGBA buffer using // the traditional TIFFReadRGBAImage() API that we trust. uint32* raster; // retrieve RGBA image uint32 *row; raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32)); if (raster == NULL) throw "No space for raster buffer"; // Read the image in one chunk into an RGBA array if(!TIFFReadRGBAImage(m_tif, width, height, raster, 1)) { _TIFFfree(raster); throw "Corrupted TIFF file!"; } // read the raster lines and save them in the DIB // with RGB mode, we have to change the order of the 3 samples RGB row = &raster[0]; bits2 = info.pImage; for (y = 0; y < height; y++) { if (info.nEscape){ // <vho> - cancel decoding _TIFFfree(raster); throw "Cancelled"; } bits = bits2; for (x = 0; x < width; x++) { *bits++ = (BYTE)TIFFGetB(row[x]); *bits++ = (BYTE)TIFFGetG(row[x]); *bits++ = (BYTE)TIFFGetR(row[x]); #if CXIMAGE_SUPPORT_ALPHA if (samplesperpixel==4) AlphaSet(x,y,(BYTE)TIFFGetA(row[x])); #endif //CXIMAGE_SUPPORT_ALPHA } row += width; bits2 += info.dwEffWidth; } _TIFFfree(raster); } else { RGBQUAD *pal; pal=(RGBQUAD*)calloc(256,sizeof(RGBQUAD)); if (pal==NULL) throw "Unable to allocate TIFF palette"; // set up the colormap based on photometric switch(photometric) { case PHOTOMETRIC_MINISBLACK: // bitmap and greyscale image types case PHOTOMETRIC_MINISWHITE: if (bitspersample == 1) { // Monochrome image if (photometric == PHOTOMETRIC_MINISBLACK) { pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; } else { pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; } } else { // need to build the scale for greyscale images if (photometric == PHOTOMETRIC_MINISBLACK) { for (DWORD i=0; i<head.biClrUsed; i++){ pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = (BYTE)(i*(255/(head.biClrUsed-1))); } } else { for (DWORD i=0; i<head.biClrUsed; i++){ pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = (BYTE)(255-i*(255/(head.biClrUsed-1))); } } } break; case PHOTOMETRIC_PALETTE: // color map indexed uint16 *red; uint16 *green; uint16 *blue; TIFFGetField(m_tif, TIFFTAG_COLORMAP, &red, &green, &blue); // Is the palette 16 or 8 bits ? BOOL Palette16Bits = FALSE; int n=1<<bitspersample; while (n-- > 0) { if (red[n] >= 256 || green[n] >= 256 || blue[n] >= 256) { Palette16Bits=TRUE; break; } } // load the palette in the DIB for (int i = (1 << bitspersample) - 1; i >= 0; i--) { if (Palette16Bits) { pal[i].rgbRed =(BYTE) CVT(red[i]); pal[i].rgbGreen = (BYTE) CVT(green[i]); pal[i].rgbBlue = (BYTE) CVT(blue[i]); } else { pal[i].rgbRed = (BYTE) red[i]; pal[i].rgbGreen = (BYTE) green[i]; pal[i].rgbBlue = (BYTE) blue[i]; } } break; } SetPalette(pal,head.biClrUsed); //palette assign free(pal); // read the tiff lines and save them in the DIB uint32 nrow; uint32 ys; int line = CalculateLine(width, bitspersample * samplesperpixel); long bitsize= TIFFStripSize(m_tif); //verify bitsize: could be wrong if StripByteCounts is missing. if (bitsize>(long)(head.biSizeImage*samplesperpixel)) bitsize=head.biSizeImage*samplesperpixel; int tiled_image = TIFFIsTiled(m_tif); uint32 tw, tl; BYTE* tilebuf; if (tiled_image){ TIFFGetField(m_tif, TIFFTAG_TILEWIDTH, &tw); TIFFGetField(m_tif, TIFFTAG_TILELENGTH, &tl); rowsperstrip = tl; bitsize = TIFFTileSize(m_tif) * (int)(1+width/tw); tilebuf = (BYTE*)malloc(TIFFTileSize(m_tif)); } bits = (BYTE*)malloc(bitsize); if (bits==NULL){ throw "CxImageTIF can't allocate memory"; } for (ys = 0; ys < height; ys += rowsperstrip) { if (info.nEscape){ // <vho> - cancel decoding free(bits); throw "Cancelled"; } nrow = (ys + rowsperstrip > height ? height - ys : rowsperstrip); if (tiled_image){ uint32 imagew = TIFFScanlineSize(m_tif); uint32 tilew = TIFFTileRowSize(m_tif); int iskew = imagew - tilew; uint8* bufp = (uint8*) bits; uint32 colb = 0; for (uint32 col = 0; col < width; col += tw) { if (TIFFReadTile(m_tif, tilebuf, col, ys, 0, 0) < 0){ free(tilebuf); free(bits); throw "Corrupted tiled TIFF file!"; } if (colb + tw > imagew) { uint32 owidth = imagew - colb; uint32 oskew = tilew - owidth; TileToStrip(bufp + colb, tilebuf, nrow, owidth, oskew + iskew, oskew ); } else { TileToStrip(bufp + colb, tilebuf, nrow, tilew, iskew, 0); } colb += tilew; } } else { if (TIFFReadEncodedStrip(m_tif, TIFFComputeStrip(m_tif, ys, 0), bits, nrow * line) == -1) { free(bits); throw "Corrupted TIFF file!"; } } for (y = 0; y < nrow; y++) { long offset=(nrow-y-1)*line; if (bitspersample==16) for (DWORD xi=0;xi<width;xi++) bits[xi+offset]=bits[xi*2+offset+1]; if (samplesperpixel==1) { //simple 8bpp image memcpy(info.pImage+info.dwEffWidth*(height-ys-nrow+y),bits+offset,info.dwEffWidth); } else if (samplesperpixel==2) { //8bpp image with alpha layer int xi=0; int ii=0; int yi=height-ys-nrow+y; while (ii<line){ SetPixelIndex(xi,yi,bits[ii+offset]); #if CXIMAGE_SUPPORT_ALPHA AlphaSet(xi,yi,bits[ii+offset+1]); #endif //CXIMAGE_SUPPORT_ALPHA ii+=2; xi++; if (xi>=(int)width){ yi--; xi=0; } } } else { //photometric==PHOTOMETRIC_CIELAB if (head.biBitCount!=24){ //fix image Create(width,height,24,CXIMAGE_FORMAT_TIF); #if CXIMAGE_SUPPORT_ALPHA if (samplesperpixel==4) AlphaCreate(); #endif //CXIMAGE_SUPPORT_ALPHA } int xi=0; int ii=0; int yi=height-ys-nrow+y; RGBQUAD c; int l,a,b,bitsoffset; double p,cx,cy,cz,cr,cg,cb; while (ii<line){ bitsoffset = ii*samplesperpixel+offset; l=bits[bitsoffset]; a=bits[bitsoffset+1]; b=bits[bitsoffset+2]; if (a>127) a-=256; if (b>127) b-=256; // lab to xyz p = (l/2.55 + 16) / 116.0; cx = pow( p + a * 0.002, 3); cy = pow( p, 3); cz = pow( p - b * 0.005, 3); // white point cx*=0.95047; //cy*=1.000; cz*=1.0883; // xyz to rgb cr = 3.240479 * cx - 1.537150 * cy - 0.498535 * cz; cg = -0.969256 * cx + 1.875992 * cy + 0.041556 * cz; cb = 0.055648 * cx - 0.204043 * cy + 1.057311 * cz; if ( cr > 0.00304 ) cr = 1.055 * pow(cr,0.41667) - 0.055; else cr = 12.92 * cr; if ( cg > 0.00304 ) cg = 1.055 * pow(cg,0.41667) - 0.055; else cg = 12.92 * cg; if ( cb > 0.00304 ) cb = 1.055 * pow(cb,0.41667) - 0.055; else cb = 12.92 * cb; c.rgbRed =(BYTE)max(0,min(255,(int)(cr*255))); c.rgbGreen=(BYTE)max(0,min(255,(int)(cg*255))); c.rgbBlue =(BYTE)max(0,min(255,(int)(cb*255))); SetPixelColor(xi,yi,c); #if CXIMAGE_SUPPORT_ALPHA if (samplesperpixel==4) AlphaSet(xi,yi,bits[bitsoffset+3]); #endif //CXIMAGE_SUPPORT_ALPHA ii++; xi++; if (xi>=(int)width){ yi--; xi=0; } } } } } free(bits); if (tiled_image) free(tilebuf); switch(orientation){ case ORIENTATION_TOPRIGHT: /* row 0 top, col 0 rhs */ Mirror(); break; case ORIENTATION_BOTRIGHT: /* row 0 bottom, col 0 rhs */ Flip(); Mirror(); break; case ORIENTATION_BOTLEFT: /* row 0 bottom, col 0 lhs */ Flip(); break; case ORIENTATION_LEFTTOP: /* row 0 lhs, col 0 top */ RotateRight(); Mirror(); break; case ORIENTATION_RIGHTTOP: /* row 0 rhs, col 0 top */ RotateLeft(); break; case ORIENTATION_RIGHTBOT: /* row 0 rhs, col 0 bottom */ RotateLeft(); Mirror(); break; case ORIENTATION_LEFTBOT: /* row 0 lhs, col 0 bottom */ RotateRight(); break; } } } catch (char *message) { strncpy(info.szLastError,message,255); if (m_tif) TIFFClose(m_tif); if (info.nEscape==-1) return true; return false; } TIFFClose(m_tif); return true; }
void DIMENSION::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); SetLayer( FlipLayer( GetLayer() ) ); }
optix::Group CornellSmall::getSceneRootGroup(optix::Context & context) { m_pgram_bounding_box = context->createProgramFromPTXFile( "parallelogram.cu.ptx", "bounds" ); m_pgram_intersection = context->createProgramFromPTXFile( "parallelogram.cu.ptx", "intersect" ); // create geometry instances QVector<optix::GeometryInstance> gis; Diffuse diffuseWhite = Diffuse(optix::make_float3( 0.8f )); Diffuse diffuseGreen = Diffuse(optix::make_float3( 0.05f, 0.8f, 0.05f )); Diffuse diffuseRed = Diffuse(optix::make_float3( 1.f, 0.05f, 0.05f )); // colors as in SmallVCM if ((m_config & CornellSmall::SmallVCMColors) != 0) { diffuseWhite = Diffuse(optix::make_float3( 0.803922f, 0.803922f, 0.803922f )); diffuseGreen = Diffuse(optix::make_float3( 0.156863f, 0.803922f, 0.172549f )); diffuseRed = Diffuse(optix::make_float3( 0.803922f, 0.152941f, 0.152941f )); } Diffuse diffuseBlue = Diffuse(optix::make_float3( 0.156863f, 0.172549f, 0.803922f )); Mirror mirror = Mirror(optix::make_float3(1.f,1.f,1.f)); Glossy glossyWhite = Glossy(optix::make_float3(.1f,.1f,.1f), optix::make_float3(.7f,.7f,.7f), 90.f); Glass glass = Glass(1.6, optix::make_float3(1.f,1.f,1.f), optix::make_float3(1.f,1.f,1.f) ); DiffuseEmitter emitter = DiffuseEmitter(m_sceneLights[0].power, Vector3(1)); // Set up materials // Floor Material *matFloor = &diffuseWhite; if ((m_config & Config::FloorMirror) != 0) { matFloor = &mirror; } else if ((m_config & Config::FloorGlossy) != 0) { matFloor = &glossyWhite; } // Ceiling Material *matCeiling = &diffuseWhite; // Back wall Material *matBackWall = &diffuseWhite; if ((m_config & Config::BackwallBlue) != 0) { matBackWall = &diffuseBlue; } // Right wall Material *matRightWall = &diffuseGreen; if ((m_config & CornellSmall::SmallVCMColors) != 0) matRightWall = &diffuseRed; // Left wall Material *matLeftWall = &diffuseRed; if ((m_config & CornellSmall::SmallVCMColors) != 0) matLeftWall = &diffuseGreen; // Short block Material *matShortBlock = &diffuseWhite; // Tall block Material *matTallBlock = &diffuseWhite; // Set geometry - Cornell box size in SmallVCM 2.56004, here rounded up slightly // Floor gis.push_back( createParallelogram(0, context, optix::make_float3( 0.0f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), optix::make_float3( 2.5f, 0.0f, 0.0f ), *matFloor ) ); // Ceiling if ((m_config & Config::LightPointDistant) == 0) { gis.push_back( createParallelogram(1, context, optix::make_float3( 0.0f, 2.5f, 0.0f ), optix::make_float3( 2.5f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), *matCeiling ) ); } // Back wall gis.push_back( createParallelogram(2, context,optix::make_float3( 0.0f, 0.0f, 2.5f), optix::make_float3( 0.0f, 2.5f, 0.0f), optix::make_float3( 2.5f, 0.0f, 0.0f), *matBackWall)); // Right wall gis.push_back( createParallelogram(3, context, optix::make_float3( 0.0f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 2.5f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), *matRightWall ) ); // Left wall gis.push_back( createParallelogram(4, context, optix::make_float3( 2.5f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), optix::make_float3( 0.0f, 2.5f, 0.0f ), *matLeftWall ) ); if ((m_config & Config::Blocks) != 0) { // Short block gis.push_back( createParallelogram(5, context, optix::make_float3( 130.0f, 165.0f, 65.0f) / 220.f, optix::make_float3( -48.0f, 0.0f, 160.0f) / 220.f, optix::make_float3( 160.0f, 0.0f, 49.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(6, context, optix::make_float3( 290.0f, 0.0f, 114.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( -50.0f, 0.0f, 158.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(7, context, optix::make_float3( 130.0f, 0.0f, 65.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( 160.0f, 0.0f, 49.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(8, context, optix::make_float3( 82.0f, 0.0f, 225.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( 48.0f, 0.0f, -160.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(9, context, optix::make_float3( 240.0f, 0.0f, 272.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, -47.0f) / 220.f, *matShortBlock)); // Tall block gis.push_back( createParallelogram(10, context, optix::make_float3( 423.0f, 340.0f, 247.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, 49.0f) / 220.f, optix::make_float3( 49.0f, 0.0f, 159.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(11, context, optix::make_float3( 423.0f, 0.0f, 247.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( 49.0f, 0.0f, 159.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(12, context, optix::make_float3( 472.0f, 0.0f, 406.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, 50.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(13, context, optix::make_float3( 314.0f, 0.0f, 456.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( -49.0f, 0.0f, -160.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(14, context, optix::make_float3( 265.0f, 0.0f, 296.0f) / 220.f, optix::make_float3( 0.0f, 340.1f, 0.0f) / 220.f, optix::make_float3( 158.0f, 0.0f, -49.0f) / 220.f, *matTallBlock ) ); } // Area light if ( ((m_config & Config::LightArea) != 0) || ((m_config & Config::LightAreaUpwards) != 0) ) { emitter.setInverseArea(m_sceneLights[0].inverseArea); for(int i = 0; i < m_sceneLights.size(); i++) { gis.push_back(createParallelogram(15 + i, context, m_sceneLights[i].position, m_sceneLights[i].v1, m_sceneLights[i].v2, emitter)); } } // Large sphere if ((m_config & Config::LargeMirrorSphere) != 0 || (m_config & Config::LargeGlassSphere) != 0) { Material *matLargeSphere = &mirror; if ((m_config & Config::LargeGlassSphere) != 0) matLargeSphere = &glass; float radius = 0.8; SphereInstance sphere = SphereInstance(*matLargeSphere, Sphere(Vector3(1.25f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Small glass sphere right if ((m_config & Config::SmallGlassSphere)) { float radius = 0.5; SphereInstance sphere = SphereInstance(glass, Sphere(Vector3(1.25f - 0.535714269f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Small mirror sphere left if ((m_config & Config::SmallMirrorSphere)) { float radius = 0.5; SphereInstance sphere = SphereInstance(mirror, Sphere(Vector3(1.25f + 0.535714269f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Create geometry group optix::GeometryGroup geometry_group = context->createGeometryGroup(); geometry_group->setChildCount( static_cast<unsigned int>( gis.size() ) ); for (int i = 0; i < gis.size(); ++i ) geometry_group->setChild( i, gis[i] ); geometry_group->setAcceleration(context->createAcceleration("NoAccel", "NoAccel")); // Bvh Sbvh Trbvh NoAccel // Bvh BvhCompact NoAccel optix::Group gro = context->createGroup(); gro->setChildCount(1); gro->setChild(0, geometry_group); optix::Acceleration acceleration = context->createAcceleration("NoAccel", "NoAccel"); gro->setAcceleration(acceleration); return gro; }