int main() { typedef int * RI; static_assert((std::is_same<RI, decltype(std::experimental::search(RI(), RI(), MySearcher()))>::value), "" ); RI it(nullptr); assert(it == std::experimental::search(it, it, MySearcher())); assert(searcher_called == 1); }
static int wrap_khp(lua_State* L) { S h=luaL_optstring(L,1,"0"); I p=luaL_optint(L,2,5000); S u=luaL_optstring(L,3,0); I t=luaL_optint(L,4,-1); if(t<0){if(!u)RI(last_connection=khp(h,p));RI(last_connection=khpu(h,p,u));} RI(last_connection=khpun(h,p,u,t)); }
static int wrap_kclose(lua_State*L) { I c=luaL_optint(L,1,-1); if(c<0) c=last_connection; kclose(c); if(c==last_connection)last_connection=-1; RI(1); }
//-------------------------------------------------------------- void ofApp::draw(){ Browser.opDraw(); ofRectangle RI(ofGetWidth()/2,0,ofGetWidth()/2,ofGetHeight()); RI.scaleFromCenter(0.99f); I.draw(RI.x,RI.y,256,256); }
static void config_read() { GetModuleFileName(GetModuleHandle(nullptr),ini_file,sizeof(ini_file)); StringCchCopy(text_file, _countof(text_file), ini_file); PathRenameExtension(ini_file, ".ini"); PathRenameExtension(text_file, ".rtf"); RI(config_x); RI(config_y); RI(config_w); RI(config_h); RI(config_border); RI(config_color); RI(config_bcolor1); RI(config_bcolor2); }
void config_read() { char *p,*ip; GetModuleFileName(hMainInstance,ini_file,sizeof(ini_file)); strcpy_s(text_file,sizeof(text_file),ini_file); p=ini_file+strlen(ini_file); ip=p; while (p >= ini_file && *p != '.') p--; strcpy_s(++p,ip-p+1,"ini"); p=text_file+strlen(text_file); ip=p; while (p >= text_file && *p != '.') p--; strcpy_s(++p,ip-p+1,"rtf"); RI(config_x); RI(config_y); RI(config_w); RI(config_h); RI(config_border); RI(config_color); RI(config_bcolor1); RI(config_bcolor2); RI(config_icon); choose_icon(config_icon); }
int main() { rep (i, N) f[i] = i; ref = 0; while (~RI(a)) { if (a == -1) { PIN(ref); rep (i, N) f[i] = i; ref = 0; continue; } RI(b); a = find(a); b = find(b); if (a == b) ref++; else f[a] = b; } return 0; }
int main(void){ int m, n; for(RI(n), RI(m); (m || n); RI(n), RI(m)){ int a, ans = 0, b, maxppa = MINPPA, ppa; FOR(i, n) cnt[i] = 0, p[i] = i; FOR(i, n) FORI(j, i + 1, n) adj[i][j] = MINPPA; FOR(i, m){ RI(a), RI(b), RI(ppa); --a; --b; if(a > b) swap(a, b); if(ppa > adj[a][b]){ adj[a][b] = ppa; maxppa = max(maxppa, ppa); } } FOR(i, n) FORI(j, i + 1, n) if(adj[i][j] == maxppa) unionfind(i, j); FOR(i, n) ans = max(ans, ++cnt[findroot(i)]); printf("%d\n", ans); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); if (aFunction.IsNull()) return 0; GEOMImpl_IRotate RI(aFunction); gp_Trsf aTrsf; gp_Pnt aCP, aP1, aP2; Standard_Integer aType = aFunction->GetType(); Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal(); if (anOriginalFunction.IsNull()) return 0; TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue(); if (anOriginal.IsNull()) return 0; if (aType == ROTATE || aType == ROTATE_COPY) { Handle(GEOM_Function) anAxis = RI.GetAxis(); if (anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if (A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir aDir(gp_Vec(aP1, aP2)); gp_Ax1 anAx1(aP1, aDir); Standard_Real anAngle = RI.GetAngle(); if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665,19769 aTrsf.SetRotation(anAx1, anAngle); //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //aShape = aTransformation.Shape(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug aTrsfOrig.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfOrig); aShape = anOriginal.Located(aLocRes); } else if (aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) { Handle(GEOM_Function) aCentPoint = RI.GetCentPoint(); Handle(GEOM_Function) aPoint1 = RI.GetPoint1(); Handle(GEOM_Function) aPoint2 = RI.GetPoint2(); if(aCentPoint.IsNull() || aPoint1.IsNull() || aPoint2.IsNull()) return 0; TopoDS_Shape aCV = aCentPoint->GetValue(); TopoDS_Shape aV1 = aPoint1->GetValue(); TopoDS_Shape aV2 = aPoint2->GetValue(); if(aCV.IsNull() || aCV.ShapeType() != TopAbs_VERTEX) return 0; if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0; if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0; aCP = BRep_Tool::Pnt(TopoDS::Vertex(aCV)); aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1)); aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2)); gp_Vec aVec1 (aCP, aP1); gp_Vec aVec2 (aCP, aP2); gp_Dir aDir (aVec1 ^ aVec2); gp_Ax1 anAx1 (aCP, aDir); Standard_Real anAngle = aVec1.Angle(aVec2); if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665 aTrsf.SetRotation(anAx1, anAngle); //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //aShape = aTransformation.Shape(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug aTrsfOrig.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfOrig); aShape = anOriginal.Located(aLocRes); } else if (aType == ROTATE_1D) { //Get direction Handle(GEOM_Function) anAxis = RI.GetAxis(); if(anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir D(gp_Vec(aP1, aP2)); gp_Ax1 AX1(aP1, D); Standard_Integer nbtimes = RI.GetNbIter1(); Standard_Real angle = 360.0/nbtimes; TopoDS_Compound aCompound; BRep_Builder B; B.MakeCompound( aCompound ); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); for (int i = 0; i < nbtimes; i++ ) { if (i == 0) { // NPAL19665 B.Add(aCompound, anOriginal); } else { aTrsf.SetRotation(AX1, i*angle/* * PI180 */); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug gp_Trsf aTrsfNew (aTrsfOrig); aTrsfNew.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfNew); B.Add(aCompound, anOriginal.Located(aLocRes)); } //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False); //B.Add(aCompound, aBRepTransformation.Shape()); } aShape = aCompound; } else if (aType == ROTATE_2D) { //Get direction Handle(GEOM_Function) anAxis = RI.GetAxis(); if(anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir D(gp_Vec(aP1, aP2)); gp_Ax1 AX1(aP1, D); gp_Trsf aTrsf1; gp_Trsf aTrsf2; gp_Trsf aTrsf3; gp_XYZ aDir2 = RI.GetDir2(); // can be set by previous execution if (aDir2.Modulus() < gp::Resolution()) { // Calculate direction as vector from the axis to the shape's center gp_Pnt P1; GProp_GProps System; if (anOriginal.ShapeType() == TopAbs_VERTEX) { P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal )); } else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) { BRepGProp::LinearProperties(anOriginal, System); P1 = System.CentreOfMass(); } else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) { BRepGProp::SurfaceProperties(anOriginal, System); P1 = System.CentreOfMass(); } else { BRepGProp::VolumeProperties(anOriginal, System); P1 = System.CentreOfMass(); } Handle(Geom_Line) Line = new Geom_Line(AX1); GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ); gp_Pnt P2 = aPrjTool.NearestPoint(); if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0; aDir2 = gp_XYZ(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()); // Attention: this abnormal action is done for good working of // TransformLikeOther(), used by RestoreSubShapes functionality RI.SetDir2(aDir2); } gp_Vec Vec (aDir2); Vec.Normalize(); gp_Vec elevVec(D); elevVec.Normalize(); Standard_Integer nbtimes2 = RI.GetNbIter2(); Standard_Integer nbtimes1 = RI.GetNbIter1(); Standard_Real step = RI.GetStep(); Standard_Real elevationstep = RI.GetElevationStep(); Standard_Real ang = RI.GetAngle(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); gp_Vec aVec; TopoDS_Compound aCompound; BRep_Builder B; B.MakeCompound( aCompound ); Standard_Real DX, DY, DZ; for (int i = 0; i < nbtimes2; i++ ) { if (i != 0) { DX = i * step * Vec.X(); DY = i * step * Vec.Y(); DZ = i * step * Vec.Z(); aVec.SetCoord( DX, DY, DZ ); aTrsf1.SetTranslation(aVec); } for (int j = 0; j < nbtimes1; j++ ) { if (j == 0) { // NPAL19665 TopLoc_Location aLocRes (aTrsf1 * aTrsfOrig); B.Add(aCompound, anOriginal.Located(aLocRes)); } else { DX = j * elevationstep * elevVec.X(); DY = j * elevationstep * elevVec.Y(); DZ = j * elevationstep * elevVec.Z(); aVec.SetCoord( DX, DY, DZ ); aTrsf3.SetTranslation(aVec); aTrsf2.SetRotation(AX1, j*ang /* * PI180 */ ); //TopLoc_Location aLocRes (aTrsf2 * aTrsf1 * aTrsfOrig); // gp_Trsf::Multiply() has a bug gp_Trsf aTrsfNew (aTrsfOrig); aTrsfNew.PreMultiply(aTrsf1); aTrsfNew.PreMultiply(aTrsf2); aTrsfNew.PreMultiply(aTrsf3); TopLoc_Location aLocRes (aTrsfNew); B.Add(aCompound, anOriginal.Located(aLocRes)); } //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aBRepTrsf1 (anOriginal, aTrsf1, Standard_False); //BRepBuilderAPI_Transform aBRepTrsf2 (aBRepTrsf1.Shape(), aTrsf2, Standard_False); //B.Add(aCompound, aBRepTrsf2.Shape()); } } aShape = aCompound; } else return 0; if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
/** \fn dumpx265Setup */ void dumpx265Setup(x265_param *param) { #define PI(x) printf(#x"\t:%d\n",(int)param->x) #define PD(x) printf(#x"\t:%d\n",(double)param->x) #define PS(x) printf(#x"\t:%s\n",param->x) printf("*************************************\n"); printf("*** Encoder Environment ***\n"); printf("*************************************\n"); PI(cpuid); PI(bEnableWavefront); #if X265_BUILD >= 47 PS(numaPools); #else PI(poolNumThreads); #endif PI(frameNumThreads); PI(logLevel); PI(bLogCuStats); PI(bEnablePsnr); PI(bEnableSsim); PI(decodedPictureHashSEI); printf("*************************************\n"); printf("** Internal Picture Specification **\n"); printf("*************************************\n"); PI(internalBitDepth); PI(internalCsp); PI(fpsNum); PI(fpsDenom); PI(sourceWidth); PI(sourceHeight); PI(levelIdc); PI(interlaceMode); PI(bRepeatHeaders); PI(bEnableAccessUnitDelimiters); PI(bEmitHRDSEI); printf("*************************************\n"); printf("*** Coding Unit (CU) Definitions ***\n"); printf("*************************************\n"); PI(maxCUSize); PI(tuQTMaxInterDepth); PI(tuQTMaxIntraDepth); printf("*************************************\n"); printf("*** GOP Structure and Lookahead ***\n"); printf("*************************************\n"); PI(bOpenGOP); PI(keyframeMin); PI(keyframeMax); PI(maxNumReferences); PI(bFrameAdaptive); PI(bframes); PI(bBPyramid); PI(lookaheadDepth); PI(bFrameBias); PI(scenecutThreshold); printf("*************************************\n"); printf("*** Intra Coding Tools ***\n"); printf("*************************************\n"); PI(bEnableConstrainedIntra); PI(bEnableStrongIntraSmoothing); printf("*************************************\n"); printf("*** Inter Coding Tools ***\n"); printf("*************************************\n"); PI(searchMethod); PI(subpelRefine); PI(searchRange); PI(maxNumMergeCand); PI(bEnableWeightedPred); PI(bEnableWeightedBiPred); printf("*************************************\n"); printf("*** Analysis Tools ***\n"); printf("*************************************\n"); PI(bEnableAMP); PI(bEnableRectInter); #if X265_BUILD < 45 PI(bEnableCbfFastMode); #endif PI(bEnableEarlySkip); PI(rdPenalty); PI(rdLevel); PD(psyRd); printf("*************************************\n"); printf("*** Coding Tools ***\n"); printf("*************************************\n"); PI(bEnableSignHiding); PI(bEnableTransformSkip); PI(bEnableTSkipFast); PI(bEnableLoopFilter); PI(bEnableSAO); #if X265_BUILD >= 33 PI(bSaoNonDeblocked); #else PI(saoLcuBoundary); #endif #if X265_BUILD < 32 PI(saoLcuBasedOptimization); #endif PI(cbQpOffset); PI(crQpOffset); PI(bIntraInBFrames); #if X265_BUILD >= 40 PI(noiseReductionIntra); PI(noiseReductionInter); #else PI(noiseReduction); #endif PI(bLossless); PI(bCULossless); #define RI(x) printf(#x"\t:%d\n",(int)param->rc.x) #define RD(x) printf(#x"\t:%f\n",(double)param->rc.x) printf("*************************************\n"); printf("*** Rate Control ***\n"); printf("*************************************\n"); RI(rateControlMode); RI(qp); RI(bitrate); #if X265_BUILD >= 41 RI(bStrictCbr); #else RD(rateTolerance); #endif RD(qCompress); RD(ipFactor); RD(pbFactor); RI(qpStep); RD(rfConstant); RI(aqMode); RD(aqStrength); RI(vbvMaxBitrate); RI(vbvBufferSize); RD(vbvBufferInit); RI(cuTree); RD(rfConstantMax); RD(rfConstantMin); RI(bStatWrite); RI(bStatRead); RD(qblur); RD(complexityBlur); #define VI(x) printf(#x"\t:%d\n",(int)param->vui.x) printf("*************************************\n"); printf("*** Video Usability Information ***\n"); printf("*************************************\n"); VI(aspectRatioIdc); VI(sarWidth); VI(sarHeight); VI(bEnableOverscanInfoPresentFlag); VI(bEnableOverscanAppropriateFlag); VI(bEnableVideoSignalTypePresentFlag); VI(videoFormat); VI(bEnableVideoFullRangeFlag); VI(bEnableColorDescriptionPresentFlag); VI(colorPrimaries); VI(transferCharacteristics); VI(matrixCoeffs); VI(bEnableChromaLocInfoPresentFlag); VI(chromaSampleLocTypeTopField); VI(chromaSampleLocTypeBottomField); VI(bEnableDefaultDisplayWindowFlag); VI(defDispWinLeftOffset); VI(defDispWinRightOffset); VI(defDispWinTopOffset); VI(defDispWinBottomOffset); }
/* this procedure is exported for the benefit of gsicc.c */ int gx_cie_real_remap_finish(cie_cached_vector3 vec3, frac * pconc, const gs_imager_state * pis, const gs_color_space *pcs) { const gs_cie_render *pcrd = pis->cie_render; const gx_cie_joint_caches *pjc = pis->cie_joint_caches; const gs_const_string *table = pcrd->RenderTable.lookup.table; int tabc[3]; /* indices for final EncodeABC lookup */ /* Apply DecodeLMN, MatrixLMN(decode), and MatrixPQR. */ if (!pjc->skipDecodeLMN) cie_lookup_map3(&vec3 /* LMN => PQR */, &pjc->DecodeLMN, "Decode/MatrixLMN+MatrixPQR"); /* Apply TransformPQR, MatrixPQR', and MatrixLMN(encode). */ if (!pjc->skipPQR) cie_lookup_map3(&vec3 /* PQR => LMN */, &pjc->TransformPQR, "Transform/Matrix'PQR+MatrixLMN"); /* Apply EncodeLMN and MatrixABC(encode). */ if (!pjc->skipEncodeLMN) cie_lookup_map3(&vec3 /* LMN => ABC */, &pcrd->caches.EncodeLMN, "EncodeLMN+MatrixABC"); /* MatrixABCEncode includes the scaling of the EncodeABC */ /* cache index. */ #define SET_TABC(i, t)\ BEGIN\ tabc[i] = cie_cached2int(vec3 /*ABC*/.t - pcrd->EncodeABC_base[i],\ _cie_interpolate_bits);\ if ((uint)tabc[i] > (gx_cie_cache_size - 1) << _cie_interpolate_bits)\ tabc[i] = (tabc[i] < 0 ? 0 :\ (gx_cie_cache_size - 1) << _cie_interpolate_bits);\ END SET_TABC(0, u); SET_TABC(1, v); SET_TABC(2, w); #undef SET_TABC if (table == 0) { /* * No further transformation. * The final mapping step includes both restriction to * the range [0..1] and conversion to fracs. */ #define EABC(i)\ cie_interpolate_fracs(pcrd->caches.EncodeABC[i].fixeds.fracs.values, tabc[i]) pconc[0] = EABC(0); pconc[1] = EABC(1); pconc[2] = EABC(2); #undef EABC return 3; } else { /* * Use the RenderTable. */ int m = pcrd->RenderTable.lookup.m; #define RT_LOOKUP(j, i) pcrd->caches.RenderTableT[j].fracs.values[i] #ifdef CIE_RENDER_TABLE_INTERPOLATE /* * The final mapping step includes restriction to the * ranges [0..dims[c]] as ints with interpolation bits. */ fixed rfix[3]; const int s = _fixed_shift - _cie_interpolate_bits; #define EABC(i)\ cie_interpolate_fracs(pcrd->caches.EncodeABC[i].fixeds.ints.values, tabc[i]) #define FABC(i, s)\ ((s) > 0) ? (EABC(i) << (s)) : (EABC(i) >> -(s)) rfix[0] = FABC(0, s); rfix[1] = FABC(1, s); rfix[2] = FABC(2, s); #undef FABC #undef EABC if_debug6('c', "[c]ABC=%g,%g,%g => iabc=%g,%g,%g\n", cie_cached2float(vec3.u), cie_cached2float(vec3.v), cie_cached2float(vec3.w), fixed2float(rfix[0]), fixed2float(rfix[1]), fixed2float(rfix[2])); gx_color_interpolate_linear(rfix, &pcrd->RenderTable.lookup, pconc); if_debug3('c', "[c] interpolated => %g,%g,%g\n", frac2float(pconc[0]), frac2float(pconc[1]), frac2float(pconc[2])); if (!pcrd->caches.RenderTableT_is_identity) { /* Map the interpolated values. */ #define frac2cache_index(v) frac2bits(v, gx_cie_log2_cache_size) pconc[0] = RT_LOOKUP(0, frac2cache_index(pconc[0])); pconc[1] = RT_LOOKUP(1, frac2cache_index(pconc[1])); pconc[2] = RT_LOOKUP(2, frac2cache_index(pconc[2])); if (m > 3) pconc[3] = RT_LOOKUP(3, frac2cache_index(pconc[3])); #undef frac2cache_index } #else /* !CIE_RENDER_TABLE_INTERPOLATE */ /* * The final mapping step includes restriction to the ranges * [0..dims[c]], plus scaling of the indices in the strings. */ #define RI(i)\ pcrd->caches.EncodeABC[i].ints.values[tabc[i] >> _cie_interpolate_bits] int ia = RI(0); int ib = RI(1); /* pre-multiplied by m * NC */ int ic = RI(2); /* pre-multiplied by m */ const byte *prtc = table[ia].data + ib + ic; /* (*pcrd->RenderTable.T)(prtc, m, pcrd, pconc); */ if_debug6('c', "[c]ABC=%g,%g,%g => iabc=%d,%d,%d\n", cie_cached2float(vec3.u), cie_cached2float(vec3.v), cie_cached2float(vec3.w), ia, ib, ic); if (pcrd->caches.RenderTableT_is_identity) { pconc[0] = byte2frac(prtc[0]); pconc[1] = byte2frac(prtc[1]); pconc[2] = byte2frac(prtc[2]); if (m > 3) pconc[3] = byte2frac(prtc[3]); } else { #if gx_cie_log2_cache_size == 8 # define byte2cache_index(b) (b) #else # if gx_cie_log2_cache_size > 8 # define byte2cache_index(b)\ ( ((b) << (gx_cie_log2_cache_size - 8)) +\ ((b) >> (16 - gx_cie_log2_cache_size)) ) # else /* < 8 */ # define byte2cache_index(b) ((b) >> (8 - gx_cie_log2_cache_size)) # endif #endif pconc[0] = RT_LOOKUP(0, byte2cache_index(prtc[0])); pconc[1] = RT_LOOKUP(1, byte2cache_index(prtc[1])); pconc[2] = RT_LOOKUP(2, byte2cache_index(prtc[2])); if (m > 3) pconc[3] = RT_LOOKUP(3, byte2cache_index(prtc[3])); #undef byte2cache_index } #endif /* !CIE_RENDER_TABLE_INTERPOLATE */ #undef RI #undef RT_LOOKUP return m; } }
void unio_stop() { RI(unio_istat); }
bool PivotCalibration2::ComputeSpinCalibration(bool snapRotation) { if (this->ToolToReferenceMatrices.size() < 10) { this->ErrorText = "Not enough input transforms are available"; return false; } if (this->GetMaximumToolOrientationDifferenceDeg() < this->MinimumOrientationDifferenceDeg) { this->ErrorText = "Not enough variation in the input transforms"; return false; } // Setup our system to find the axis of rotation unsigned int rows = 3, columns = 3; vnl_matrix<double> A(rows, columns, 0); vnl_matrix<double> I(3, 3, 0); I.set_identity(); vnl_matrix<double> RI(rows, columns); // this will store the maximum difference in orientation between the first transform and all the other transforms double maximumOrientationDifferenceDeg = 0; std::vector< vtkSmartPointer<vtkMatrix4x4> >::const_iterator previt = this->ToolToReferenceMatrices.end(); for (std::vector< vtkSmartPointer<vtkMatrix4x4> >::const_iterator it = this->ToolToReferenceMatrices.begin(); it != this->ToolToReferenceMatrices.end(); it++) { if (previt == this->ToolToReferenceMatrices.end()) { previt = it; continue; // No comparison to make for the first matrix } vtkSmartPointer< vtkMatrix4x4 > itinverse = vtkSmartPointer< vtkMatrix4x4 >::New(); vtkMatrix4x4::Invert((*it), itinverse); vtkSmartPointer< vtkMatrix4x4 > instRotation = vtkSmartPointer< vtkMatrix4x4 >::New(); vtkMatrix4x4::Multiply4x4(itinverse, (*previt), instRotation); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { RI(i, j) = instRotation->GetElement(i, j); } } RI = RI - I; A = A + RI.transpose() * RI; previt = it; } // Note: If the needle orientation protocol changes, only the definitions of shaftAxis and secondaryAxes need to be changed // Define the shaft axis and the secondary shaft axis // Current needle orientation protocol dictates: shaft axis -z, orthogonal axis +x // If StylusX is parallel to ShaftAxis then: shaft axis -z, orthogonal axis +y vnl_vector<double> shaftAxis_Shaft(columns, 0); shaftAxis_Shaft(0) = 0; shaftAxis_Shaft(1) = 0; shaftAxis_Shaft(2) = -1; vnl_vector<double> orthogonalAxis_Shaft(columns, 0); orthogonalAxis_Shaft(0) = 1; orthogonalAxis_Shaft(1) = 0; orthogonalAxis_Shaft(2) = 0; vnl_vector<double> backupAxis_Shaft(columns, 0); backupAxis_Shaft(0) = 0; backupAxis_Shaft(1) = 1; backupAxis_Shaft(2) = 0; // Find the eigenvector associated with the smallest eigenvalue // This is the best axis of rotation over all instantaneous rotations vnl_matrix<double> eigenvectors(columns, columns, 0); vnl_vector<double> eigenvalues(columns, 0); vnl_symmetric_eigensystem_compute(A, eigenvectors, eigenvalues); // Note: eigenvectors are ordered in increasing eigenvalue ( 0 = smallest, end = biggest ) vnl_vector<double> shaftAxis_ToolTip(columns, 0); shaftAxis_ToolTip(0) = eigenvectors(0, 0); shaftAxis_ToolTip(1) = eigenvectors(1, 0); shaftAxis_ToolTip(2) = eigenvectors(2, 0); shaftAxis_ToolTip.normalize(); // Snap the direction vector to be exactly aligned with one of the coordinate axes // This is if the sensor is known to be parallel to one of the axis, just not which one if (snapRotation) { int closestCoordinateAxis = element_product(shaftAxis_ToolTip, shaftAxis_ToolTip).arg_max(); shaftAxis_ToolTip.fill(0); shaftAxis_ToolTip.put(closestCoordinateAxis, 1); // Doesn't matter the direction, will be sorted out in the next step } // Make sure it is in the correct direction (opposite the StylusTipToStylus translation) vnl_vector<double> toolTipToToolTranslation(3); toolTipToToolTranslation(0) = this->ToolTipToToolMatrix->GetElement(0, 3); toolTipToToolTranslation(1) = this->ToolTipToToolMatrix->GetElement(1, 3); toolTipToToolTranslation(2) = this->ToolTipToToolMatrix->GetElement(2, 3); if (dot_product(shaftAxis_ToolTip, toolTipToToolTranslation) > 0) { shaftAxis_ToolTip = shaftAxis_ToolTip * (-1); } //set the RMSE this->SpinRMSE = (A * shaftAxis_ToolTip).rms(); // If the secondary axis 1 is parallel to the shaft axis in the tooltip frame, then use secondary axis 2 vnl_vector<double> orthogonalAxis_ToolTip; double angle = acos(dot_product(shaftAxis_ToolTip, orthogonalAxis_Shaft)); // Force angle to be between -pi/2 and +pi/2 if (angle > vtkMath::Pi() / 2) { angle -= vtkMath::Pi(); } if (angle < -vtkMath::Pi() / 2) { angle += vtkMath::Pi(); } if (fabs(angle) > vtkMath::RadiansFromDegrees(PARALLEL_ANGLE_THRESHOLD_DEGREES)) // If shaft axis and orthogonal axis are not parallel { orthogonalAxis_ToolTip = orthogonalAxis_Shaft; } else { orthogonalAxis_ToolTip = backupAxis_Shaft; } // Do the registration find the appropriate rotation orthogonalAxis_ToolTip = orthogonalAxis_ToolTip - dot_product(orthogonalAxis_ToolTip, shaftAxis_ToolTip) * shaftAxis_ToolTip; orthogonalAxis_ToolTip.normalize(); // Register X,Y,O points in the two coordinate frames (only spherical registration - since pure rotation) vnl_matrix<double> ToolTipPoints(3, 3, 0.0); vnl_matrix<double> ShaftPoints(3, 3, 0.0); ToolTipPoints.put(0, 0, shaftAxis_ToolTip(0)); ToolTipPoints.put(0, 1, shaftAxis_ToolTip(1)); ToolTipPoints.put(0, 2, shaftAxis_ToolTip(2)); ToolTipPoints.put(1, 0, orthogonalAxis_ToolTip(0)); ToolTipPoints.put(1, 1, orthogonalAxis_ToolTip(1)); ToolTipPoints.put(1, 2, orthogonalAxis_ToolTip(2)); ToolTipPoints.put(2, 0, 0); ToolTipPoints.put(2, 1, 0); ToolTipPoints.put(2, 2, 0); ShaftPoints.put(0, 0, shaftAxis_Shaft(0)); ShaftPoints.put(0, 1, shaftAxis_Shaft(1)); ShaftPoints.put(0, 2, shaftAxis_Shaft(2)); ShaftPoints.put(1, 0, orthogonalAxis_Shaft(0)); ShaftPoints.put(1, 1, orthogonalAxis_Shaft(1)); ShaftPoints.put(1, 2, orthogonalAxis_Shaft(2)); ShaftPoints.put(2, 0, 0); ShaftPoints.put(2, 1, 0); ShaftPoints.put(2, 2, 0); vnl_svd<double> ShaftToToolTipRegistrator(ShaftPoints.transpose() * ToolTipPoints); vnl_matrix<double> V = ShaftToToolTipRegistrator.V(); vnl_matrix<double> U = ShaftToToolTipRegistrator.U(); vnl_matrix<double> Rotation = V * U.transpose(); // Make sure the determinant is positve (i.e. +1) double determinant = vnl_determinant(Rotation); if (determinant < 0) { // Switch the sign of the third column of V if the determinant is not +1 // This is the recommended approach from Huang et al. 1987 V.put(0, 2, -V.get(0, 2)); V.put(1, 2, -V.get(1, 2)); V.put(2, 2, -V.get(2, 2)); Rotation = V * U.transpose(); } // Set the elements of the output matrix for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { this->ToolTipToToolMatrix->SetElement(i, j, Rotation[i][j]); } } this->ErrorText.empty(); return true; }
STATIC void flow_write_step(FLOW_PARAM unsigned int *hi, unsigned int *lo) { #define RI() do { \ *hi=0; \ *lo=F_w_times[W_IDLE]; \ return; \ } while(0) #define R(_x) do { \ if(_x) { \ *hi=F_w_times[W_MARK|W_ONE]; \ *lo=F_w_times[W_SPACE|W_ONE]; \ } else { \ *hi=F_w_times[W_MARK|W_ZERO]; \ *lo=F_w_times[W_SPACE|W_ZERO]; \ } \ return; \ } while(0) if(F_writer_state == FW_idle) { //DBG("W idle"); RI(); } else if(F_writer_state == FW_sync) { F_writer_bit ++; if (F_writer_bit > F_w_sync) { F_writer_state = FW_data; F_writer_bit = 0; //DBG("W last_syn"); R(1); } else { //DBG("W syn"); R(0); } } else if(F_writer_byte >= F_writer_len) { F_writer_state = FW_idle; //DBG("W end_bit"); R(0); } else if(F_writer_bit >= F_bits) { //DBG("W parity"); F_writer_bit ++; unsigned char bit; switch(F_parity) { default: case P_NONE: flow_error("Oops Parity"); *hi=0; *lo=0; return; case P_MARK: bit=1; break; case P_SPACE: bit=0; break; case P_ODD: bit=F_writer_parity^1; break; case P_EVEN: bit=F_writer_parity; break; } F_writer_byte++; F_writer_bit=0; F_writer_parity=0; R(bit & 1); } else { //DBGS("W bit %u/%u",F_writer_byte,F_writer_bit); unsigned char bit; if(F_msb) bit = F_writer_data[F_writer_byte] >> (F_bits-1-F_writer_bit); else bit = F_writer_data[F_writer_byte] >> F_writer_bit; F_writer_bit ++; F_writer_parity ^= bit; if(F_writer_bit == F_bits && F_writer_parity == P_NONE) { F_writer_byte++; F_writer_bit=0; F_writer_parity=0; } R(bit & 1); }
void ReadConfig() { RS(flac_cfg.title.tag_format, sizeof(flac_cfg.title.tag_format), default_format); if (flac_cfg.title.tag_format_w) free(flac_cfg.title.tag_format_w); flac_cfg.title.tag_format_w = convert_ansi_to_wide_(flac_cfg.title.tag_format); /* @@@ FIXME: trailing spaces */ RS(flac_cfg.title.sep, sizeof(flac_cfg.title.sep), default_sep); RI(flac_cfg.tag.reserve_space, 1); RI(flac_cfg.display.show_bps, 1); RI(flac_cfg.output.misc.stop_err, 0); RI(flac_cfg.output.replaygain.enable, 1); RI(flac_cfg.output.replaygain.album_mode, 0); RI(flac_cfg.output.replaygain.hard_limit, 0); RI(flac_cfg.output.replaygain.preamp, 0); RI(flac_cfg.output.resolution.normal.dither_24_to_16, 0); RI(flac_cfg.output.resolution.replaygain.dither, 0); RI(flac_cfg.output.resolution.replaygain.noise_shaping, 1); RI(flac_cfg.output.resolution.replaygain.bps_out, 16); }