<commit_before>void Config()
{
    // 7-DEC-2000 09:00
    // Switch on Transition Radiation simulation. 6/12/00 18:00
    // iZDC=1  7/12/00 09:00
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00

    // Set Random Number seed
    // gRandom->SetSeed(12345);

    new     AliGeant3("C++ Interface to Geant3");

    if (!gSystem->Getenv("CONFIG_FILE"))
    {
        TFile  *rootfile = new TFile("galice.root", "recreate");

        rootfile->SetCompressionLevel(2);
    }

    TGeant3 *geant3 = (TGeant3 *) gMC;

    //
    // Set External decayer
    AliDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //
    //
    //=======================================================================
    // ******* GEANT STEERING parameters FOR ALICE SIMULATION *******
    geant3->SetTRIG(1);         //Number of events to be processed
    geant3->SetSWIT(4, 10);
    geant3->SetDEBU(0, 0, 1);
    //geant3->SetSWIT(2,2);
    geant3->SetDCAY(1);
    geant3->SetPAIR(1);
    geant3->SetCOMP(1);
    geant3->SetPHOT(1);
    geant3->SetPFIS(0);
    geant3->SetDRAY(0);
    geant3->SetANNI(1);
    geant3->SetBREM(1);
    geant3->SetMUNU(1);
    geant3->SetCKOV(1);
    geant3->SetHADR(1);         //Select pure GEANH (HADR 1) or GEANH/NUCRIN (HADR 3)
    geant3->SetLOSS(2);
    geant3->SetMULS(1);
    geant3->SetRAYL(1);
    geant3->SetAUTO(1);         //Select automatic STMIN etc... calc. (AUTO 1) or manual (AUTO 0)
    geant3->SetABAN(0);         //Restore 3.16 behaviour for abandoned tracks
    geant3->SetOPTI(2);         //Select optimisation level for GEANT geometry searches (0,1,2)
    geant3->SetERAN(5.e-7);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    //             GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA TOFMAX
    geant3->SetCUTS(cut, cut, cut, cut, cut, cut, cut, cut, cut, cut,
                    tofmax);
    //
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        int     nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    } else
    {
        int     nParticles = 50;
    }
    AliGenHIJINGpara *gener = new AliGenHIJINGpara(nParticles);

    gener->SetMomentumRange(0, 999);
    gener->SetPhiRange(0, 360);
    //  gener->SetThetaRange(0.28,179.72);
    gener->SetThetaRange(0., 180.);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position
    gener->Init();
    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);

    gAlice->SetField(-999, 2);  //Specify maximum magnetic field in Tesla (neg. ==> default field)

    Int_t   iABSO = 1;
    Int_t   iCASTOR = 1;
    Int_t   iDIPO = 1;
    Int_t   iFMD = 1;
    Int_t   iFRAME = 1;
    Int_t   iHALL = 1;
    Int_t   iITS = 1;
    Int_t   iMAG = 1;
    Int_t   iMUON = 1;
    Int_t   iPHOS = 1;
    Int_t   iPIPE = 1;
    Int_t   iPMD = 1;
    Int_t   iRICH = 1;
    Int_t   iSHIL = 1;
    Int_t   iSTART = 1;
    Int_t   iTOF = 1;
    Int_t   iTPC = 1;
    Int_t   iTRD = 1;
    Int_t   iZDC = 1;

    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv0("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv2("DIPO", "Dipole version 2");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALL("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAME *FRAME = new AliFRAMEv2("FRAME", "Space Frame");

    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILv0("SHIL", "Shielding");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv0("PIPE", "Beam Pipe");
    }

  if(iITS) {

//=================== ITS parameters ============================
    //
    // As the innermost detector in ALICE, the Inner Tracking System "impacts" on
    // almost all other detectors. This involves the fact that the ITS geometry
    // still has several options to be followed in parallel in order to determine
    // the best set-up which minimizes the induced background. All the geometries
    // available to date are described in the following. Read carefully the comments
    // and use the default version (the only one uncommented) unless you are making
    // comparisons and you know what you are doing. In this case just uncomment the
    // ITS geometry you want to use and run Aliroot.
    //
    // Detailed geometries:
    //
    //
    //AliITS *ITS  = new AliITSv5symm("ITS","Updated ITS TDR detailed version with symmetric services");
    //
    //AliITS *ITS  = new AliITSv5asymm("ITS","Updates ITS TDR detailed version with asymmetric services");
    //
    AliITSvPPRasymm *ITS  = new AliITSvPPRasymm("ITS","New ITS PPR detailed version with asymmetric services");
    ITS->SetMinorVersion(2);                                         // don't touch this parameter if you're not an ITS developer
    ITS->SetReadDet(kFALSE);                                         // don't touch this parameter if you're not an ITS developer
    ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymm2.det");  // don't touch this parameter if you're not an ITS developer
    ITS->SetThicknessDet1(300.);   // detector thickness on layer 1 must be in the range [100,300]
    ITS->SetThicknessDet2(300.);   // detector thickness on layer 2 must be in the range [100,300]
    ITS->SetThicknessChip1(300.);  // chip thickness on layer 1 must be in the range [150,300]
    ITS->SetThicknessChip2(300.);  // chip thickness on layer 2 must be in the range [150,300]
    ITS->SetRails(1);	           // 1 --> rails in ; 0 --> rails out
    ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //AliITSvPPRsymm *ITS  = new AliITSvPPRsymm("ITS","New ITS PPR detailed version with symmetric services");
    //ITS->SetMinorVersion(2);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetReadDet(kFALSE);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRsymm2.det"); // don't touch this parameter if you're not an ITS developer
    //ITS->SetThicknessDet1(300.);   // detector thickness on layer 1 must be in the range [100,300]
    //ITS->SetThicknessDet2(300.);   // detector thickness on layer 2 must be in the range [100,300]
    //ITS->SetThicknessChip1(300.);  // chip thickness on layer 1 must be in the range [150,300]
    //ITS->SetThicknessChip2(300.);  // chip thickness on layer 2 must be in the range [150,300]
    //ITS->SetRails(1);              // 1 --> rails in ; 0 --> rails out
    //ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //
    // Coarse geometries (warning: no hits are produced with these coarse geometries and they unuseful
    // for reconstruction !):
    //
    //
    //AliITSvPPRcoarseasymm *ITS  = new AliITSvPPRcoarseasymm("ITS","New ITS PPR coarse version with asymmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //AliITS *ITS  = new AliITSvPPRcoarsesymm("ITS","New ITS PPR coarse version with symmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //
    //
    // Geant3 <-> EUCLID conversion
    // ============================
    //
    // SetEUCLID is a flag to output (=1) or not to output (=0) both geometry and
    // media to two ASCII files (called by default ITSgeometry.euc and
    // ITSgeometry.tme) in a format understandable to the CAD system EUCLID.
    // The default (=0) means that you dont want to use this facility.
    //
    ITS->SetEUCLID(0);
  }

    if (iTPC)
    {
        //============================ TPC parameters ================================
        // --- This allows the user to specify sectors for the SLOW (TPC geometry 2)
        // --- Simulator. SecAL (SecAU) <0 means that ALL lower (upper)
        // --- sectors are specified, any value other than that requires at least one
        // --- sector (lower or upper)to be specified!
        // --- Reminder: sectors 1-24 are lower sectors (1-12 -> z>0, 13-24 -> z<0)
        // ---           sectors 25-72 are the upper ones (25-48 -> z>0, 49-72 -> z<0)
        // --- SecLows - number of lower sectors specified (up to 6)
        // --- SecUps - number of upper sectors specified (up to 12)
        // --- Sens - sensitive strips for the Slow Simulator !!!
        // --- This does NOT work if all S or L-sectors are specified, i.e.
        // --- if SecAL or SecAU < 0
        //
        //
        //-----------------------------------------------------------------------------

        //  gROOT->LoadMacro("SetTPCParam.C");
        //  AliTPCParam *param = SetTPCParam();
        AliTPC *TPC = new AliTPCv2("TPC", "Default");

        // All sectors included
        TPC->SetSecAL(-1);
        TPC->SetSecAU(-1);

    }

    if (iTOF)
    {
        //=================== TOF parameters ============================
        AliTOF *TOF = new AliTOFv2("TOF", "normal TOF");
    }

    if (iRICH)
    {
        //=================== RICH parameters ===========================
        AliRICH *RICH = new AliRICHv1("RICH", "normal RICH");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv1("ZDC", "normal ZDC");
    }

    if (iCASTOR)
    {
        //=================== CASTOR parameters ============================

        AliCASTOR *CASTOR = new AliCASTORv1("CASTOR", "normal CASTOR");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");

        // Select the gas mixture (0: 97% Xe + 3% isobutane, 1: 90% Xe + 10% CO2)
        TRD->SetGasMix(1);

        // With hole in front of PHOS
        TRD->SetPHOShole();
        // With hole in front of RICH
        TRD->SetRICHhole();
        // Switch on TR
        AliTRDsim *TRDsim = TRD->CreateTR();
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================

        AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
    }

    if (iMUON)
    {
        //=================== MUON parameters ===========================

        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "GPS2");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================

        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");

        PMD->SetPAR(1., 1., 0.8, 0.02);
        PMD->SetIN(6., 18., -580., 27., 27.);
        PMD->SetGEO(0.0, 0.2, 4.);
        PMD->SetPadSize(0.8, 1.0, 1.0, 1.5);

    }

    if (iSTART)
    {
        //=================== START parameters ============================
        AliSTART *START = new AliSTARTv1("START", "START Detector");
    }

}
<commit_msg>ITS->SetWriteDet(...) commented<commit_after>void Config()
{
    // 7-DEC-2000 09:00
    // Switch on Transition Radiation simulation. 6/12/00 18:00
    // iZDC=1  7/12/00 09:00
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00

    // Set Random Number seed
    // gRandom->SetSeed(12345);

    new     AliGeant3("C++ Interface to Geant3");

    if (!gSystem->Getenv("CONFIG_FILE"))
    {
        TFile  *rootfile = new TFile("galice.root", "recreate");

        rootfile->SetCompressionLevel(2);
    }

    TGeant3 *geant3 = (TGeant3 *) gMC;

    //
    // Set External decayer
    AliDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //
    //
    //=======================================================================
    // ******* GEANT STEERING parameters FOR ALICE SIMULATION *******
    geant3->SetTRIG(1);         //Number of events to be processed
    geant3->SetSWIT(4, 10);
    geant3->SetDEBU(0, 0, 1);
    //geant3->SetSWIT(2,2);
    geant3->SetDCAY(1);
    geant3->SetPAIR(1);
    geant3->SetCOMP(1);
    geant3->SetPHOT(1);
    geant3->SetPFIS(0);
    geant3->SetDRAY(0);
    geant3->SetANNI(1);
    geant3->SetBREM(1);
    geant3->SetMUNU(1);
    geant3->SetCKOV(1);
    geant3->SetHADR(1);         //Select pure GEANH (HADR 1) or GEANH/NUCRIN (HADR 3)
    geant3->SetLOSS(2);
    geant3->SetMULS(1);
    geant3->SetRAYL(1);
    geant3->SetAUTO(1);         //Select automatic STMIN etc... calc. (AUTO 1) or manual (AUTO 0)
    geant3->SetABAN(0);         //Restore 3.16 behaviour for abandoned tracks
    geant3->SetOPTI(2);         //Select optimisation level for GEANT geometry searches (0,1,2)
    geant3->SetERAN(5.e-7);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    //             GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA TOFMAX
    geant3->SetCUTS(cut, cut, cut, cut, cut, cut, cut, cut, cut, cut,
                    tofmax);
    //
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        int     nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    } else
    {
        int     nParticles = 50;
    }
    AliGenHIJINGpara *gener = new AliGenHIJINGpara(nParticles);

    gener->SetMomentumRange(0, 999);
    gener->SetPhiRange(0, 360);
    //  gener->SetThetaRange(0.28,179.72);
    gener->SetThetaRange(0., 180.);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position
    gener->Init();
    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);

    gAlice->SetField(-999, 2);  //Specify maximum magnetic field in Tesla (neg. ==> default field)

    Int_t   iABSO = 1;
    Int_t   iCASTOR = 1;
    Int_t   iDIPO = 1;
    Int_t   iFMD = 1;
    Int_t   iFRAME = 1;
    Int_t   iHALL = 1;
    Int_t   iITS = 1;
    Int_t   iMAG = 1;
    Int_t   iMUON = 1;
    Int_t   iPHOS = 1;
    Int_t   iPIPE = 1;
    Int_t   iPMD = 1;
    Int_t   iRICH = 1;
    Int_t   iSHIL = 1;
    Int_t   iSTART = 1;
    Int_t   iTOF = 1;
    Int_t   iTPC = 1;
    Int_t   iTRD = 1;
    Int_t   iZDC = 1;

    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv0("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv2("DIPO", "Dipole version 2");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALL("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAME *FRAME = new AliFRAMEv2("FRAME", "Space Frame");

    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILv0("SHIL", "Shielding");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv0("PIPE", "Beam Pipe");
    }

  if(iITS) {

//=================== ITS parameters ============================
    //
    // As the innermost detector in ALICE, the Inner Tracking System "impacts" on
    // almost all other detectors. This involves the fact that the ITS geometry
    // still has several options to be followed in parallel in order to determine
    // the best set-up which minimizes the induced background. All the geometries
    // available to date are described in the following. Read carefully the comments
    // and use the default version (the only one uncommented) unless you are making
    // comparisons and you know what you are doing. In this case just uncomment the
    // ITS geometry you want to use and run Aliroot.
    //
    // Detailed geometries:
    //
    //
    //AliITS *ITS  = new AliITSv5symm("ITS","Updated ITS TDR detailed version with symmetric services");
    //
    //AliITS *ITS  = new AliITSv5asymm("ITS","Updates ITS TDR detailed version with asymmetric services");
    //
    AliITSvPPRasymm *ITS  = new AliITSvPPRasymm("ITS","New ITS PPR detailed version with asymmetric services");
    ITS->SetMinorVersion(2);                                         // don't touch this parameter if you're not an ITS developer
    ITS->SetReadDet(kFALSE);                                         // don't touch this parameter if you're not an ITS developer
    //    ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymm2.det");  // don't touch this parameter if you're not an ITS developer
    ITS->SetThicknessDet1(300.);   // detector thickness on layer 1 must be in the range [100,300]
    ITS->SetThicknessDet2(300.);   // detector thickness on layer 2 must be in the range [100,300]
    ITS->SetThicknessChip1(300.);  // chip thickness on layer 1 must be in the range [150,300]
    ITS->SetThicknessChip2(300.);  // chip thickness on layer 2 must be in the range [150,300]
    ITS->SetRails(1);	           // 1 --> rails in ; 0 --> rails out
    ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //AliITSvPPRsymm *ITS  = new AliITSvPPRsymm("ITS","New ITS PPR detailed version with symmetric services");
    //ITS->SetMinorVersion(2);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetReadDet(kFALSE);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRsymm2.det"); // don't touch this parameter if you're not an ITS developer
    //ITS->SetThicknessDet1(300.);   // detector thickness on layer 1 must be in the range [100,300]
    //ITS->SetThicknessDet2(300.);   // detector thickness on layer 2 must be in the range [100,300]
    //ITS->SetThicknessChip1(300.);  // chip thickness on layer 1 must be in the range [150,300]
    //ITS->SetThicknessChip2(300.);  // chip thickness on layer 2 must be in the range [150,300]
    //ITS->SetRails(1);              // 1 --> rails in ; 0 --> rails out
    //ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //
    // Coarse geometries (warning: no hits are produced with these coarse geometries and they unuseful
    // for reconstruction !):
    //
    //
    //AliITSvPPRcoarseasymm *ITS  = new AliITSvPPRcoarseasymm("ITS","New ITS PPR coarse version with asymmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //AliITS *ITS  = new AliITSvPPRcoarsesymm("ITS","New ITS PPR coarse version with symmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //
    //
    // Geant3 <-> EUCLID conversion
    // ============================
    //
    // SetEUCLID is a flag to output (=1) or not to output (=0) both geometry and
    // media to two ASCII files (called by default ITSgeometry.euc and
    // ITSgeometry.tme) in a format understandable to the CAD system EUCLID.
    // The default (=0) means that you dont want to use this facility.
    //
    ITS->SetEUCLID(0);
  }

    if (iTPC)
    {
        //============================ TPC parameters ================================
        // --- This allows the user to specify sectors for the SLOW (TPC geometry 2)
        // --- Simulator. SecAL (SecAU) <0 means that ALL lower (upper)
        // --- sectors are specified, any value other than that requires at least one
        // --- sector (lower or upper)to be specified!
        // --- Reminder: sectors 1-24 are lower sectors (1-12 -> z>0, 13-24 -> z<0)
        // ---           sectors 25-72 are the upper ones (25-48 -> z>0, 49-72 -> z<0)
        // --- SecLows - number of lower sectors specified (up to 6)
        // --- SecUps - number of upper sectors specified (up to 12)
        // --- Sens - sensitive strips for the Slow Simulator !!!
        // --- This does NOT work if all S or L-sectors are specified, i.e.
        // --- if SecAL or SecAU < 0
        //
        //
        //-----------------------------------------------------------------------------

        //  gROOT->LoadMacro("SetTPCParam.C");
        //  AliTPCParam *param = SetTPCParam();
        AliTPC *TPC = new AliTPCv2("TPC", "Default");

        // All sectors included
        TPC->SetSecAL(-1);
        TPC->SetSecAU(-1);

    }

    if (iTOF)
    {
        //=================== TOF parameters ============================
        AliTOF *TOF = new AliTOFv2("TOF", "normal TOF");
    }

    if (iRICH)
    {
        //=================== RICH parameters ===========================
        AliRICH *RICH = new AliRICHv1("RICH", "normal RICH");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv1("ZDC", "normal ZDC");
    }

    if (iCASTOR)
    {
        //=================== CASTOR parameters ============================

        AliCASTOR *CASTOR = new AliCASTORv1("CASTOR", "normal CASTOR");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");

        // Select the gas mixture (0: 97% Xe + 3% isobutane, 1: 90% Xe + 10% CO2)
        TRD->SetGasMix(1);

        // With hole in front of PHOS
        TRD->SetPHOShole();
        // With hole in front of RICH
        TRD->SetRICHhole();
        // Switch on TR
        AliTRDsim *TRDsim = TRD->CreateTR();
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================

        AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
    }

    if (iMUON)
    {
        //=================== MUON parameters ===========================

        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "GPS2");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================

        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");

        PMD->SetPAR(1., 1., 0.8, 0.02);
        PMD->SetIN(6., 18., -580., 27., 27.);
        PMD->SetGEO(0.0, 0.2, 4.);
        PMD->SetPadSize(0.8, 1.0, 1.0, 1.5);

    }

    if (iSTART)
    {
        //=================== START parameters ============================
        AliSTART *START = new AliSTARTv1("START", "START Detector");
    }

}
<|endoftext|>


<commit_before>
#include "util/Assert.h"

#include "store/naive/simple_pul.h"
#include "store/naive/node_items.h"
#include "store/naive/atomic_items.h"

namespace zorba { namespace store {

/*******************************************************************************

********************************************************************************/
void PULImpl::addInsertAttributes(Item* target, std::vector<XmlNode*>& attrs)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    InsertAttributesPrimitive* upd = new InsertAttributesPrimitive(n, attrs);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::DELETE)
        return;
    }

    InsertAttributesPrimitive* upd = new InsertAttributesPrimitive(n, attrs);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************
  Create a delete primitive in "this" pul for the given node, if another delete
  for the same node does not exist already.
********************************************************************************/
void PULImpl::addDelete(Item* target)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    DeletePrimitive* upd = new DeletePrimitive(n);
    theDeleteList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::PUL_DELETE)
        return;
    }

    DeletePrimitive* upd = new DeletePrimitive(n);
    theDeleteList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addReplaceValue(Item* target, xqpStringStore* newValue)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    ReplaceValuePrimitive* upd = new ReplaceValuePrimitive(n, newValue);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ReplaceValuePrimitive* upd = new ReplaceValuePrimitive(n, newValue);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addReplaceContent(Item* target, Item* newChild)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);
  XmlNode* child = reinterpret_cast<XmlNode*>(newChild);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    ReplaceContentPrimitive* upd = new ReplaceContentPrimitive(n, child);
    theReplaceContentList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::REPLACE_CONTENT)
      {
        ZORBA_ERROR_ALERT(ZorbaError::XUDY0017, NULL, DONT_CONTINUE_EXECUTION, "", "");
      }
    }

    ReplaceContentPrimitive* upd = new ReplaceContentPrimitive(n, child);
    theReplaceContentList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addRename(Item* target, Item* newName)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);
  QNameItemImpl* qn = reinterpret_cast<QNameItemImpl*>(newName);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    RenamePrimitive* upd = new RenamePrimitive(n, qn);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::RENAME)
      {
        ZORBA_ERROR_ALERT(ZorbaError::XUDY0015, NULL, DONT_CONTINUE_EXECUTION, "", "");
      }
    }

    RenamePrimitive* upd = new RenamePrimitive(n, qn);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::mergeUpdates(const PUL& other)
{
}

/*******************************************************************************

********************************************************************************/
void PULImpl::applyUpdates()
{
  ulong i;
  ulong numUpdates;

  numUpdates = theDoFirstList.size();
  for (i = 0; i < numUpdates; i++)
    theDoFirstList[i]->apply();

  numUpdates = theInsertList.size();
  for (i = 0; i < numUpdates; i++)
    theInsertList[i]->apply();

  numUpdates = theReplaceNodeList.size();
  for (i = 0; i < numUpdates; i++)
    theReplaceNodeList[i]->apply();

  numUpdates = theReplaceContentList.size();
  for (i = 0; i < numUpdates; i++)
    theReplaceContentList[i]->apply();

  numUpdates = theDeleteList.size();
  for (i = 0; i < numUpdates; i++)
    theDeleteList[i]->apply();

  numUpdates = theDeleteList.size();
  for (i = 0; i < numUpdates; i++)
    theDeleteList[i]->theTarget->switchTree();
}

/*******************************************************************************

********************************************************************************/
void PULImpl::verify()
{
}

/*******************************************************************************

********************************************************************************/
void InsertAttributesPrimitive::apply()
{
  theTarget->insertAttributes(theAttributes);
}

/*******************************************************************************

********************************************************************************/
void DeletePrimitive::apply()
{
  theTarget->disconnect();
}

/*******************************************************************************

********************************************************************************/
void ReplaceValuePrimitive::apply()
{
  theTarget->replaceValue(theNewValue, theOldValue);
}

/*******************************************************************************

********************************************************************************/
void ReplaceContentPrimitive::apply()
{
  theTarget->replaceElementContent(theNewChild, theOldChildren);
}

/*******************************************************************************

********************************************************************************/
void RenamePrimitive::apply()
{
  theTarget->rename(theNewName, theOldName);
}

}
}
<commit_msg>compilation fix<commit_after>
#include "util/Assert.h"

#include "store/naive/simple_pul.h"
#include "store/naive/node_items.h"
#include "store/naive/atomic_items.h"

namespace zorba { namespace store {

/*******************************************************************************

********************************************************************************/
void PULImpl::addInsertAttributes(Item* target, std::vector<XmlNode*>& attrs)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    InsertAttributesPrimitive* upd = new InsertAttributesPrimitive(n, attrs);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::PUL_DELETE)
        return;
    }

    InsertAttributesPrimitive* upd = new InsertAttributesPrimitive(n, attrs);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************
  Create a delete primitive in "this" pul for the given node, if another delete
  for the same node does not exist already.
********************************************************************************/
void PULImpl::addDelete(Item* target)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    DeletePrimitive* upd = new DeletePrimitive(n);
    theDeleteList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::PUL_DELETE)
        return;
    }

    DeletePrimitive* upd = new DeletePrimitive(n);
    theDeleteList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addReplaceValue(Item* target, xqpStringStore* newValue)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    ReplaceValuePrimitive* upd = new ReplaceValuePrimitive(n, newValue);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ReplaceValuePrimitive* upd = new ReplaceValuePrimitive(n, newValue);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addReplaceContent(Item* target, Item* newChild)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);
  XmlNode* child = reinterpret_cast<XmlNode*>(newChild);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    ReplaceContentPrimitive* upd = new ReplaceContentPrimitive(n, child);
    theReplaceContentList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::REPLACE_CONTENT)
      {
        ZORBA_ERROR_ALERT(ZorbaError::XUDY0017, NULL, DONT_CONTINUE_EXECUTION, "", "");
      }
    }

    ReplaceContentPrimitive* upd = new ReplaceContentPrimitive(n, child);
    theReplaceContentList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::addRename(Item* target, Item* newName)
{
  ZORBA_ASSERT(target->isNode());

  XmlNode* n = reinterpret_cast<XmlNode*>(target);
  QNameItemImpl* qn = reinterpret_cast<QNameItemImpl*>(newName);

  theTreeRoots.insert(n->getTree()->getRoot());

  NodeUpdates* updatesp;
  bool found = theNodeToUpdatesMap.get(n, updatesp);

  if (!found)
  {
    RenamePrimitive* upd = new RenamePrimitive(n, qn);
    theDoFirstList.push_back(upd);

    NodeUpdates updates(1);
    updates[0] = upd;
    updatesp = &updates;
    theNodeToUpdatesMap.insert(n, updatesp);
  }
  else
  {
    ulong numUpdates = updatesp->size();

    for (ulong i = 0; i < numUpdates; i++)
    {
      if ((*updatesp)[i]->getKind() == UpdateConsts::RENAME)
      {
        ZORBA_ERROR_ALERT(ZorbaError::XUDY0015, NULL, DONT_CONTINUE_EXECUTION, "", "");
      }
    }

    RenamePrimitive* upd = new RenamePrimitive(n, qn);
    theDoFirstList.push_back(upd);
    updatesp->push_back(upd);
  }
}

/*******************************************************************************

********************************************************************************/
void PULImpl::mergeUpdates(const PUL& other)
{
}

/*******************************************************************************

********************************************************************************/
void PULImpl::applyUpdates()
{
  ulong i;
  ulong numUpdates;

  numUpdates = theDoFirstList.size();
  for (i = 0; i < numUpdates; i++)
    theDoFirstList[i]->apply();

  numUpdates = theInsertList.size();
  for (i = 0; i < numUpdates; i++)
    theInsertList[i]->apply();

  numUpdates = theReplaceNodeList.size();
  for (i = 0; i < numUpdates; i++)
    theReplaceNodeList[i]->apply();

  numUpdates = theReplaceContentList.size();
  for (i = 0; i < numUpdates; i++)
    theReplaceContentList[i]->apply();

  numUpdates = theDeleteList.size();
  for (i = 0; i < numUpdates; i++)
    theDeleteList[i]->apply();

  numUpdates = theDeleteList.size();
  for (i = 0; i < numUpdates; i++)
    theDeleteList[i]->theTarget->switchTree();
}

/*******************************************************************************

********************************************************************************/
void PULImpl::verify()
{
}

/*******************************************************************************

********************************************************************************/
void InsertAttributesPrimitive::apply()
{
  theTarget->insertAttributes(theAttributes);
}

/*******************************************************************************

********************************************************************************/
void DeletePrimitive::apply()
{
  theTarget->disconnect();
}

/*******************************************************************************

********************************************************************************/
void ReplaceValuePrimitive::apply()
{
  theTarget->replaceValue(theNewValue, theOldValue);
}

/*******************************************************************************

********************************************************************************/
void ReplaceContentPrimitive::apply()
{
  theTarget->replaceElementContent(theNewChild, theOldChildren);
}

/*******************************************************************************

********************************************************************************/
void RenamePrimitive::apply()
{
  theTarget->rename(theNewName, theOldName);
}

}
}
<|endoftext|>


<commit_before>/*
 * LightsaberObjectMenuComponent.cpp
 *
 *  Created on: 3/11/2012
 *      Author: kyle
 */

#include "server/zone/objects/creature/CreatureObject.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/objects/player/sui/colorbox/SuiColorBox.h"
#include "GogglesObjectMenuComponent.h"
#include "server/zone/objects/scene/components/ObjectMenuComponent.h"
#include "server/zone/packets/object/ObjectMenuResponse.h"
#include "server/zone/managers/objectcontroller/ObjectController.h"
#include "server/zone/objects/player/sui/SuiCallback.h"
#include "server/zone/objects/player/sui/callbacks/ColorGogglesSuiCallback.h"
#include "server/zone/Zone.h"
#include "server/zone/ZoneServer.h"
#include "server/zone/templates/customization/AssetCustomizationManagerTemplate.h"

void GogglesObjectMenuComponent::fillObjectMenuResponse(SceneObject* sceneObject, ObjectMenuResponse* menuResponse, CreatureObject* player) {

	if (!sceneObject->isTangibleObject())
		return;

	TangibleObjectMenuComponent::fillObjectMenuResponse(sceneObject, menuResponse, player);

	// Coloring the goggles...

	String text = "Color Change";
	menuResponse->addRadialMenuItem(81, 3, text);

}

int GogglesObjectMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {
	if (!sceneObject->isTangibleObject())
		return 0;

	if (!sceneObject->isASubChildOf(player))
		return 0;

	if (selectedID == 81) {

		ManagedReference<SceneObject*> parent = sceneObject->getParent();
		if (parent != NULL && parent->isPlayerCreature()) {
			player->sendSystemMessage("@error_message:equipped_goggles");
			return 0;
		}

		// Handle color change.

		ZoneServer* server = player->getZoneServer();

		if (server != NULL) {

			// The color index.
			String appearanceFilename = sceneObject->getObjectTemplate()->getAppearanceFilename();
			VectorMap<String, Reference<CustomizationVariable*> > variables;
			AssetCustomizationManagerTemplate::instance()->getCustomizationVariables(appearanceFilename.hashCode(), variables, false);

			// The Sui Box.
			ManagedReference<SuiColorBox*> cbox = new SuiColorBox(player, SuiWindowType::COLOR_GOGGLES);
			cbox->setCallback(new ColorGogglesSuiCallback(server));
			cbox->setColorPalette(variables.elementAt(1).getKey()); // First one seems to be the frame of it? Skip to 2nd.
			cbox->setUsingObject(sceneObject);

			// Add to player.
			ManagedReference<PlayerObject*> ghost = player->getPlayerObject();
			ghost->addSuiBox(cbox);
			player->sendMessage(cbox->generateMessage());
		}

	}

	return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
}
<commit_msg>[added] Ability to color the frames of special edition goggles_s01 - mantis 3826<commit_after>/*
 * LightsaberObjectMenuComponent.cpp
 *
 *  Created on: 3/11/2012
 *      Author: kyle
 */

#include "server/zone/objects/creature/CreatureObject.h"
#include "server/zone/objects/player/PlayerObject.h"
#include "server/zone/objects/player/sui/colorbox/SuiColorBox.h"
#include "GogglesObjectMenuComponent.h"
#include "server/zone/objects/scene/components/ObjectMenuComponent.h"
#include "server/zone/packets/object/ObjectMenuResponse.h"
#include "server/zone/managers/objectcontroller/ObjectController.h"
#include "server/zone/objects/player/sui/SuiCallback.h"
#include "server/zone/objects/player/sui/callbacks/ColorGogglesSuiCallback.h"
#include "server/zone/Zone.h"
#include "server/zone/ZoneServer.h"
#include "server/zone/templates/customization/AssetCustomizationManagerTemplate.h"

void GogglesObjectMenuComponent::fillObjectMenuResponse(SceneObject* sceneObject, ObjectMenuResponse* menuResponse, CreatureObject* player) {

	if (!sceneObject->isTangibleObject())
		return;

	TangibleObjectMenuComponent::fillObjectMenuResponse(sceneObject, menuResponse, player);

	if (sceneObject->isASubChildOf(player)) {
		menuResponse->addRadialMenuItem(81, 3, "@sui:color_lens");

		if (sceneObject->getObjectTemplate()->getFullTemplateString() == "object/tangible/wearables/goggles/goggles_s01.iff")
			menuResponse->addRadialMenuItem(82, 3, "@sui:color_frame");
	}
}

int GogglesObjectMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {
	if (!sceneObject->isTangibleObject())
		return 0;

	if (!sceneObject->isASubChildOf(player))
		return 0;

	if (selectedID == 81 || selectedID == 82) {

		ManagedReference<SceneObject*> parent = sceneObject->getParent();
		if (parent != NULL && parent->isPlayerCreature()) {
			player->sendSystemMessage("@error_message:equipped_goggles");
			return 0;
		}

		// Handle color change.

		ZoneServer* server = player->getZoneServer();

		if (server != NULL) {

			// The color index.
			String appearanceFilename = sceneObject->getObjectTemplate()->getAppearanceFilename();
			VectorMap<String, Reference<CustomizationVariable*> > variables;
			AssetCustomizationManagerTemplate::instance()->getCustomizationVariables(appearanceFilename.hashCode(), variables, false);

			// The Sui Box.
			ManagedReference<SuiColorBox*> cbox = new SuiColorBox(player, SuiWindowType::COLOR_GOGGLES);
			cbox->setCallback(new ColorGogglesSuiCallback(server));
			if (selectedID == 81)
				cbox->setColorPalette(variables.elementAt(1).getKey());
			else
				cbox->setColorPalette(variables.elementAt(0).getKey());
			cbox->setUsingObject(sceneObject);

			// Add to player.
			ManagedReference<PlayerObject*> ghost = player->getPlayerObject();
			ghost->addSuiBox(cbox);
			player->sendMessage(cbox->generateMessage());
		}

	}

	return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
}
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
    //w.setControlsVisible(false);
    w.showMaximized();
#else
    w.show();
#endif
    return a.exec();
}
<commit_msg>MapViewer: Made controls invisible by default on devices.<commit_after>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
    w.setControlsVisible(false);
    w.showMaximized();
#else
    w.show();
#endif
    return a.exec();
}
<|endoftext|>


<commit_before>/**
 * \file
 * \brief ChipInputPin class header for GPIOv1 in STM32
 *
 * \author Copyright (C) 2016 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_
#define SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_

#include "distortos/chip/STM32-GPIOv1.hpp"

#include "distortos/devices/io/InputPin.hpp"

namespace distortos
{

namespace chip
{

/**
 * ChipInputPin class is a single input pin of GPIOv1 in STM32
 *
 * \ingroup devices
 */

class ChipInputPin : public devices::InputPin
{
public:

	/**
	 * \brief ChipInputPin's constructor
	 *
	 * \param [in] pin is the identifier of pin
	 * \param [in] pull is the desired pull-up/pull-down configuration of pin, default - PinPull::none
	 * \param [in] inverted selects whether the pin is inverted (true) - get() returns true when GPIO state is low and
	 * false when GPIO state is high - or not (false), default - false, not inverted
	 */

	explicit ChipInputPin(Pin pin, PinPull pull = {}, bool inverted = {});

	/**
	 * \return current state of pin
	 */

	bool get() const override;

protected:

	/**
	 * \brief Enables or disables inverted mode.
	 *
	 * \param [in] inverted selects whether the pin is inverted (true) or not (false)
	 */

	void setInvertedMode(const bool inverted)
	{
		inverted_ = inverted;
	}

private:

	/// identifier of pin
	Pin pin_;

	/// selects whether the pin is inverted (true) or not (false)
	bool inverted_;
};

}	// namespace chip

}	// namespace distortos

#endif	// SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_
<commit_msg>Add protected ChipInputPin::getInvertedMode() for STM32 GPIOv1<commit_after>/**
 * \file
 * \brief ChipInputPin class header for GPIOv1 in STM32
 *
 * \author Copyright (C) 2016 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_
#define SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_

#include "distortos/chip/STM32-GPIOv1.hpp"

#include "distortos/devices/io/InputPin.hpp"

namespace distortos
{

namespace chip
{

/**
 * ChipInputPin class is a single input pin of GPIOv1 in STM32
 *
 * \ingroup devices
 */

class ChipInputPin : public devices::InputPin
{
public:

	/**
	 * \brief ChipInputPin's constructor
	 *
	 * \param [in] pin is the identifier of pin
	 * \param [in] pull is the desired pull-up/pull-down configuration of pin, default - PinPull::none
	 * \param [in] inverted selects whether the pin is inverted (true) - get() returns true when GPIO state is low and
	 * false when GPIO state is high - or not (false), default - false, not inverted
	 */

	explicit ChipInputPin(Pin pin, PinPull pull = {}, bool inverted = {});

	/**
	 * \return current state of pin
	 */

	bool get() const override;

protected:

	/**
	 * \return true if inverted mode is enabled, false otherwise
	 */

	bool getInvertedMode() const
	{
		return inverted_;
	}

	/**
	 * \brief Enables or disables inverted mode.
	 *
	 * \param [in] inverted selects whether the pin is inverted (true) or not (false)
	 */

	void setInvertedMode(const bool inverted)
	{
		inverted_ = inverted;
	}

private:

	/// identifier of pin
	Pin pin_;

	/// selects whether the pin is inverted (true) or not (false)
	bool inverted_;
};

}	// namespace chip

}	// namespace distortos

#endif	// SOURCE_CHIP_STM32_PERIPHERALS_GPIOV1_INCLUDE_DISTORTOS_CHIP_CHIPINPUTPIN_HPP_
<|endoftext|>


<commit_before>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkSubtractConstantFromImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int itkSubtractConstantFromImageFilterTest( int, char* [] )
{

  // Define the dimension of the images
  const unsigned int ImageDimension = 3;

  // Declare the types of the images
  typedef float                                   PixelType;
  typedef itk::Image< PixelType, ImageDimension > InputImageType;
  typedef itk::Image< PixelType, ImageDimension > OutputImageType;
  typedef float                                   FactorType;

  // Declare appropriate iterator types
  typedef itk::ImageRegionIteratorWithIndex<
                                  InputImageType >  InputIteratorType;

  typedef itk::ImageRegionIteratorWithIndex<
                                  OutputImageType > OutputIteratorType;

  // Declare the type of the index to access images
  typedef itk::Index< ImageDimension >         IndexType;

  // Declare the type of the size
  typedef itk::Size< ImageDimension >          SizeType;

  // Create the input image
  typedef itk::ImageRegion< ImageDimension >   RegionType;

  // Create two images
  InputImageType::Pointer inputImage = InputImageType::New();

  // Define its size, and start index
  SizeType size;
  size[0] = 2;
  size[1] = 2;
  size[2] = 2;

  IndexType start;
  start[0] = 0;
  start[1] = 0;
  start[2] = 0;

  RegionType region;
  region.SetIndex( start );
  region.SetSize( size );

  // Initialize image
  inputImage->SetLargestPossibleRegion( region );
  inputImage->SetBufferedRegion( region );
  inputImage->SetRequestedRegion( region );
  inputImage->Allocate();

  // Initialize the content of the input image
  const double value = itk::Math::pi / 6.0;
  inputImage->FillBuffer( value );

  // Declare the type for the SubtractConstantFromImageFilter filter
  typedef itk::SubtractConstantFromImageFilter<
    InputImageType, FactorType, OutputImageType > FilterType;

  // Create the filter
  FilterType::Pointer filter = FilterType::New();

  EXERCISE_BASIC_OBJECT_METHODS( filter, SubtractConstantFromImageFilter,
    BinaryFunctorImageFilter );

  // Set the input image
  filter->SetInput( inputImage );

  // Get the filter output
  OutputImageType::Pointer outputImage = filter->GetOutput();

  const FactorType factor = 17.0;
  filter->SetConstant( factor );
  TEST_SET_GET_VALUE( factor, filter->GetConstant() );

  // Execute the filter
  TRY_EXPECT_NO_EXCEPTION( filter->Update() );

  // Create an iterator for going through the image output
  OutputIteratorType ot( outputImage, outputImage->GetRequestedRegion() );

  // Check the content of the result image
  ot.GoToBegin();
  it.GoToBegin();
  while( !ot.IsAtEnd() )
    {
    const InputImageType::PixelType  input  = it.Get();
    const OutputImageType::PixelType output = ot.Get();
    const float expectedValue = input - factor;
    if( !itk::Math::ExactlyEquals( expectedValue, output ) )
      {
      std::cerr << "Test failed!" << std::endl;
      std::cerr << "Error in pixel value at index [" << ot.GetIndex() << "]" << std::endl;
      std::cerr << "Expected: " << expectedValue
        << ", but got " << output << std::endl;
      return EXIT_FAILURE;
      }
    ++ot;
    ++it;
    }

  FilterType::Pointer filter2 = FilterType::New();
  filter2 = filter;
  if( filter2 != filter )
    {
    std::cout << "Test failed!" << std::endl;
    std::cout << "Error: operator = failed." << std::endl;
    return EXIT_FAILURE;
    }

  std::cout << "Test finished." << std::endl;
  return EXIT_SUCCESS;
}
<commit_msg>BUG: Add missing input image iterator declaration.<commit_after>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkSubtractConstantFromImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int itkSubtractConstantFromImageFilterTest( int, char* [] )
{

  // Define the dimension of the images
  const unsigned int ImageDimension = 3;

  // Declare the types of the images
  typedef float                                   PixelType;
  typedef itk::Image< PixelType, ImageDimension > InputImageType;
  typedef itk::Image< PixelType, ImageDimension > OutputImageType;
  typedef float                                   FactorType;

  // Declare appropriate iterator types
  typedef itk::ImageRegionIteratorWithIndex<
                                  InputImageType >  InputIteratorType;

  typedef itk::ImageRegionIteratorWithIndex<
                                  OutputImageType > OutputIteratorType;

  // Declare the type of the index to access images
  typedef itk::Index< ImageDimension >         IndexType;

  // Declare the type of the size
  typedef itk::Size< ImageDimension >          SizeType;

  // Create the input image
  typedef itk::ImageRegion< ImageDimension >   RegionType;

  // Create two images
  InputImageType::Pointer inputImage = InputImageType::New();

  // Define its size, and start index
  SizeType size;
  size[0] = 2;
  size[1] = 2;
  size[2] = 2;

  IndexType start;
  start[0] = 0;
  start[1] = 0;
  start[2] = 0;

  RegionType region;
  region.SetIndex( start );
  region.SetSize( size );

  // Initialize image
  inputImage->SetLargestPossibleRegion( region );
  inputImage->SetBufferedRegion( region );
  inputImage->SetRequestedRegion( region );
  inputImage->Allocate();

  // Initialize the content of the input image
  const double value = itk::Math::pi / 6.0;
  inputImage->FillBuffer( value );

  // Declare the type for the SubtractConstantFromImageFilter filter
  typedef itk::SubtractConstantFromImageFilter<
    InputImageType, FactorType, OutputImageType > FilterType;

  // Create the filter
  FilterType::Pointer filter = FilterType::New();

  EXERCISE_BASIC_OBJECT_METHODS( filter, SubtractConstantFromImageFilter,
    BinaryFunctorImageFilter );

  // Set the input image
  filter->SetInput( inputImage );

  // Get the filter output
  OutputImageType::Pointer outputImage = filter->GetOutput();

  const FactorType factor = 17.0;
  filter->SetConstant( factor );
  TEST_SET_GET_VALUE( factor, filter->GetConstant() );

  // Execute the filter
  TRY_EXPECT_NO_EXCEPTION( filter->Update() );

  // Create iterators for going through the images
  InputIteratorType it( inputImage, inputImage->GetBufferedRegion() );
  OutputIteratorType ot( outputImage, outputImage->GetRequestedRegion() );

  // Check the content of the result image
  ot.GoToBegin();
  it.GoToBegin();
  while( !ot.IsAtEnd() )
    {
    const InputImageType::PixelType  input  = it.Get();
    const OutputImageType::PixelType output = ot.Get();
    const float expectedValue = input - factor;
    if( !itk::Math::ExactlyEquals( expectedValue, output ) )
      {
      std::cerr << "Test failed!" << std::endl;
      std::cerr << "Error in pixel value at index [" << ot.GetIndex() << "]" << std::endl;
      std::cerr << "Expected: " << expectedValue
        << ", but got " << output << std::endl;
      return EXIT_FAILURE;
      }
    ++ot;
    ++it;
    }

  FilterType::Pointer filter2 = FilterType::New();
  filter2 = filter;
  if( filter2 != filter )
    {
    std::cout << "Test failed!" << std::endl;
    std::cout << "Error: operator = failed." << std::endl;
    return EXIT_FAILURE;
    }

  std::cout << "Test finished." << std::endl;
  return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>/*=========================================================================

 Program:   Medical Imaging & Interaction Toolkit
 Language:  C++
 Date:      $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $
 Version:   $Revision: 21975 $

 Copyright (c) German Cancer Research Center, Division of Medical and
 Biological Informatics. All rights reserved.
 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

 =========================================================================*/

//misc
#define _USE_MATH_DEFINES
#include <math.h>

// Blueberry
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>

// Qmitk
#include "QmitkDwiSoftwarePhantomView.h"

// MITK
#include <mitkImage.h>
#include <mitkDiffusionImage.h>
#include <mitkImageToItk.h>
#include <itkDwiPhantomGenerationFilter.h>
#include <mitkImageCast.h>
#include <mitkProperties.h>

const std::string QmitkDwiSoftwarePhantomView::VIEW_ID = "org.mitk.views.dwisoftwarephantomview";

QmitkDwiSoftwarePhantomView::QmitkDwiSoftwarePhantomView()
    : QmitkFunctionality()
    , m_Controls( 0 )
    , m_MultiWidget( NULL )
{

}

// Destructor
QmitkDwiSoftwarePhantomView::~QmitkDwiSoftwarePhantomView()
{

}

void QmitkDwiSoftwarePhantomView::CreateQtPartControl( QWidget *parent )
{
    // build up qt view, unless already done
    if ( !m_Controls )
    {
        // create GUI widgets from the Qt Designer's .ui file
        m_Controls = new Ui::QmitkDwiSoftwarePhantomViewControls;
        m_Controls->setupUi( parent );
        m_Controls->m_SignalRegionBox->setVisible(false);

        connect((QObject*) m_Controls->m_GeneratePhantomButton, SIGNAL(clicked()), (QObject*) this, SLOT(GeneratePhantom()));
    }
}

template<int ndirs>
std::vector<itk::Vector<double,3> > QmitkDwiSoftwarePhantomView::MakeGradientList()
{
    std::vector<itk::Vector<double,3> > retval;
    vnl_matrix_fixed<double, 3, ndirs>* U =
            itk::PointShell<ndirs, vnl_matrix_fixed<double, 3, ndirs> >::DistributePointShell();

    // Add 0 vector for B0
    int numB0 = ndirs/10;
    if (numB0==0)
        numB0=1;
    itk::Vector<double,3> v;
    v.Fill(0.0);
    for (int i=0; i<numB0; i++)
    {
        retval.push_back(v);
    }

    for(int i=0; i<ndirs;i++)
    {
        itk::Vector<double,3> v;
        v[0] = U->get(0,i); v[1] = U->get(1,i); v[2] = U->get(2,i);
        retval.push_back(v);
    }

    return retval;
}

void QmitkDwiSoftwarePhantomView::GeneratePhantom()
{
    typedef itk::DwiPhantomGenerationFilter< short > FilterType;
    FilterType::GradientListType gradientList;

    m_SignalRegions.clear();
    for (int i=0; i<m_SignalRegionNodes.size(); i++)
    {
        mitk::Image::Pointer mitkBinaryImg = dynamic_cast<mitk::Image*>(m_SignalRegionNodes.at(i)->GetData());
        ItkUcharImgType::Pointer signalRegion = ItkUcharImgType::New();
        mitk::CastToItkImage<ItkUcharImgType>(mitkBinaryImg, signalRegion);
        m_SignalRegions.push_back(signalRegion);
    }

    switch(m_Controls->m_TensorsToDWINumDirsSelect->currentIndex())
    {
    case 0:
        gradientList = MakeGradientList<12>();
        break;
    case 1:
        gradientList = MakeGradientList<42>();
        break;
    case 2:
        gradientList = MakeGradientList<92>();
        break;
    case 3:
        gradientList = MakeGradientList<162>();
        break;
    case 4:
        gradientList = MakeGradientList<252>();
        break;
    case 5:
        gradientList = MakeGradientList<362>();
        break;
    case 6:
        gradientList = MakeGradientList<492>();
        break;
    case 7:
        gradientList = MakeGradientList<642>();
        break;
    case 8:
        gradientList = MakeGradientList<812>();
        break;
    case 9:
        gradientList = MakeGradientList<1002>();
        break;
    default:
        gradientList = MakeGradientList<92>();
    }
    double bVal = m_Controls->m_TensorsToDWIBValueEdit->value();
    itk::ImageRegion<3> imageRegion;
    imageRegion.SetSize(0, m_Controls->m_SizeX->value());
    imageRegion.SetSize(1, m_Controls->m_SizeY->value());
    imageRegion.SetSize(2, m_Controls->m_SizeZ->value());
    mitk::Vector3D spacing;
    spacing[0] = m_Controls->m_SpacingX->value();
    spacing[1] = m_Controls->m_SpacingY->value();
    spacing[2] = m_Controls->m_SpacingZ->value();

    FilterType::Pointer filter = FilterType::New();
    filter->SetGradientList(gradientList);
    filter->SetBValue(bVal);
    filter->SetSNR(m_Controls->m_NoiseLevel->value());
    filter->SetSignalScale(m_Controls->m_SignalScale->value());
    filter->SetImageRegion(imageRegion);
    filter->SetSpacing(spacing);
    filter->SetSignalRegions(m_SignalRegions);
    filter->SetGreyMatterAdc(m_Controls->m_GmAdc->value());

    std::vector< float >                            tensorFA;
    std::vector< float >                            tensorADC;
    std::vector< float >                            tensorWeight;
    std::vector< vnl_vector_fixed<double, 3> >      tensorDirection;
    for (int i=0; i<m_SpinFa.size(); i++)
    {
        tensorFA.push_back(m_SpinFa.at(i)->value());
        tensorADC.push_back(m_SpinAdc.at(i)->value());
        vnl_vector_fixed<double, 3> dir;
        dir[0] = m_SpinX.at(i)->value();
        dir[1] = m_SpinY.at(i)->value();
        dir[2] = m_SpinZ.at(i)->value();
        dir.normalize();
        tensorDirection.push_back(dir);
        tensorWeight.push_back(m_SpinWeight.at(i)->value());
    }
    filter->SetTensorFA(tensorFA);
    filter->SetTensorADC(tensorADC);
    filter->SetTensorWeight(tensorWeight);
    filter->SetTensorDirection(tensorDirection);
    filter->Update();

    mitk::DiffusionImage<short>::Pointer image = mitk::DiffusionImage<short>::New();
    image->SetVectorImage( filter->GetOutput() );
    image->SetB_Value(bVal);
    image->SetDirections(gradientList);
    image->InitializeFromVectorImage();
    mitk::DataNode::Pointer node = mitk::DataNode::New();
    node->SetData( image );
    node->SetName(m_Controls->m_ImageName->text().toStdString());
    GetDataStorage()->Add(node);

    if (m_Controls->m_OutputNumDirectionsBox->isChecked())
    {
        ItkUcharImgType::Pointer numDirImage = filter->GetNumDirectionsImage();
        mitk::Image::Pointer image2 = mitk::Image::New();
        image2->InitializeByItk( numDirImage.GetPointer() );
        image2->SetVolume( numDirImage->GetBufferPointer() );
        mitk::DataNode::Pointer node2 = mitk::DataNode::New();
        node2->SetData(image2);
        QString name(m_Controls->m_ImageName->text());
        name += "_NumDirections";
        node2->SetName(name.toStdString().c_str());
        GetDataStorage()->Add(node2);
    }

    if (m_SignalRegionNodes.size()==0)
        return;

    if (m_Controls->m_OutputDirectionImagesBox->isChecked())
    {
        typedef typename FilterType::ItkDirectionImageContainer ItkDirectionImageContainer;
        typename ItkDirectionImageContainer::Pointer container = filter->GetDirectionImageContainer();
        for (int i=0; i<container->Size(); i++)
        {
            typename FilterType::ItkDirectionImage::Pointer itkImg = container->GetElement(i);
            mitk::Image::Pointer img = mitk::Image::New();
            img->InitializeByItk( itkImg.GetPointer() );
            img->SetVolume( itkImg->GetBufferPointer() );
            mitk::DataNode::Pointer node = mitk::DataNode::New();
            node->SetData(img);
            QString name(m_Controls->m_ImageName->text());
            name += "_Direction";
            name += QString::number(i+1);
            node->SetName(name.toStdString().c_str());
            GetDataStorage()->Add(node);
        }
    }

    if (m_Controls->m_OutputVectorFieldBox->isChecked())
    {
        mitk::Geometry3D::Pointer geometry = image->GetGeometry();
        mitk::Vector3D outImageSpacing = geometry->GetSpacing();
        float minSpacing = 1;
        if(outImageSpacing[0]<outImageSpacing[1] && outImageSpacing[0]<outImageSpacing[2])
            minSpacing = outImageSpacing[0];
        else if (outImageSpacing[1] < outImageSpacing[2])
            minSpacing = outImageSpacing[1];
        else
            minSpacing = outImageSpacing[2];

        mitk::FiberBundleX::Pointer directions = filter->GetOutputFiberBundle();
        directions->SetGeometry(geometry);
        mitk::DataNode::Pointer node = mitk::DataNode::New();
        node->SetData(directions);
        QString name(m_Controls->m_ImageName->text());
        name += "_VectorField";
        node->SetName(name.toStdString().c_str());
        node->SetProperty("Fiber2DSliceThickness", mitk::FloatProperty::New(minSpacing));
        node->SetProperty("Fiber2DfadeEFX", mitk::BoolProperty::New(false));
        GetDataStorage()->Add(node);
    }
}

void QmitkDwiSoftwarePhantomView::UpdateGui()
{
    if (!m_SignalRegionNodes.empty())
    {
        m_Controls->m_SignalRegionBox->setVisible(true);
        m_Controls->m_Instruction->setVisible(false);
    }
    else
    {
        m_Controls->m_SignalRegionBox->setVisible(false);
        m_Controls->m_Instruction->setVisible(true);
    }

    QLayout* layout = m_Controls->m_SignalRegionBox->layout();

    for (int i=0; i<m_Labels.size(); i++)
    {
        delete m_Labels.at(i);
    }
    for (int i=0; i<m_SpinFa.size(); i++)
    {
        delete m_SpinFa.at(i);
        delete m_SpinAdc.at(i);
        delete m_SpinX.at(i);
        delete m_SpinY.at(i);
        delete m_SpinZ.at(i);
        delete m_SpinWeight.at(i);
    }
    m_Labels.clear();
    m_SpinFa.clear();
    m_SpinAdc.clear();
    m_SpinX.clear();
    m_SpinY.clear();
    m_SpinZ.clear();
    m_SpinWeight.clear();

    if (layout)
        delete layout;

    QGridLayout* newlayout = new QGridLayout();

    m_Controls->m_SignalRegionBox->setLayout(newlayout);

    if (!m_SignalRegionNodes.empty())
    {
        QLabel* label1 = new QLabel("Image");
        newlayout->addWidget(label1,0,0);
        m_Labels.push_back(label1);
        QLabel* label2 = new QLabel("FA");
        newlayout->addWidget(label2,0,1);
        m_Labels.push_back(label2);
        QLabel* label3 = new QLabel("ADC");
        newlayout->addWidget(label3,0,2);
        m_Labels.push_back(label3);
        QLabel* label4 = new QLabel("X");
        newlayout->addWidget(label4,0,03);
        m_Labels.push_back(label4);
        QLabel* label5 = new QLabel("Y");
        newlayout->addWidget(label5,0,4);
        m_Labels.push_back(label5);
        QLabel* label6 = new QLabel("Z");
        newlayout->addWidget(label6,0,5);
        m_Labels.push_back(label6);
        QLabel* label7 = new QLabel("Weight");
        newlayout->addWidget(label7,0,6);
        m_Labels.push_back(label7);
    }
    for (int i=0; i<m_SignalRegionNodes.size(); i++)
    {
        QLabel* label = new QLabel(m_SignalRegionNodes.at(i)->GetName().c_str());
        newlayout->addWidget(label,i+1,0);
        m_Labels.push_back(label);

        QDoubleSpinBox* spinFa = new QDoubleSpinBox();
        spinFa->setValue(0.7);
        spinFa->setMinimum(0);
        spinFa->setMaximum(1);
        spinFa->setSingleStep(0.1);
        newlayout->addWidget(spinFa,i+1,1);
        m_SpinFa.push_back(spinFa);

        QDoubleSpinBox* spinAdc = new QDoubleSpinBox();
        newlayout->addWidget(spinAdc,i+1,2);
        spinAdc->setMinimum(0);
        spinAdc->setMaximum(1);
        spinAdc->setSingleStep(0.001);
        spinAdc->setDecimals(3);
        spinAdc->setValue(0.001); ///// ???????????????????????????
        m_SpinAdc.push_back(spinAdc);

        QDoubleSpinBox* spinX = new QDoubleSpinBox();
        newlayout->addWidget(spinX,i+1,3);
        spinX->setValue(1);
        spinX->setMinimum(-1);
        spinX->setMaximum(1);
        spinX->setSingleStep(0.1);
        m_SpinX.push_back(spinX);

        QDoubleSpinBox* spinY = new QDoubleSpinBox();
        newlayout->addWidget(spinY,i+1,4);
        spinY->setMinimum(-1);
        spinY->setMaximum(1);
        spinY->setSingleStep(0.1);
        m_SpinY.push_back(spinY);

        QDoubleSpinBox* spinZ = new QDoubleSpinBox();
        newlayout->addWidget(spinZ,i+1,5);
        spinZ->setMinimum(-1);
        spinZ->setMaximum(1);
        spinZ->setSingleStep(0.1);
        m_SpinZ.push_back(spinZ);

        QDoubleSpinBox* spinWeight = new QDoubleSpinBox();
        newlayout->addWidget(spinWeight,i+1,6);
        spinWeight->setMinimum(0);
        spinWeight->setMaximum(1);
        spinWeight->setSingleStep(0.1);
        spinWeight->setValue(1.0);
        m_SpinWeight.push_back(spinWeight);
    }
}

void QmitkDwiSoftwarePhantomView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
{
    m_MultiWidget = &stdMultiWidget;
}

void QmitkDwiSoftwarePhantomView::StdMultiWidgetNotAvailable()
{
    m_MultiWidget = NULL;
}

void QmitkDwiSoftwarePhantomView::OnSelectionChanged( std::vector<mitk::DataNode*> nodes )
{
    if ( !this->IsVisible() )
    {
        // do nothing if nobody wants to see me :-(
        return;
    }

    m_SignalRegionNodes.clear();

    // iterate all selected objects, adjust warning visibility
    for( std::vector<mitk::DataNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it )
    {
        mitk::DataNode::Pointer node = *it;

        if( node.IsNotNull() && dynamic_cast<mitk::Image*>(node->GetData()) )
        {
            bool isBinary = false;
            node->GetPropertyValue<bool>("binary", isBinary);
            if (isBinary)
                m_SignalRegionNodes.push_back(node);
        }
    }
    UpdateGui();
}
<commit_msg>COMP: removed typename<commit_after>/*=========================================================================

 Program:   Medical Imaging & Interaction Toolkit
 Language:  C++
 Date:      $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $
 Version:   $Revision: 21975 $

 Copyright (c) German Cancer Research Center, Division of Medical and
 Biological Informatics. All rights reserved.
 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

 =========================================================================*/

//misc
#define _USE_MATH_DEFINES
#include <math.h>

// Blueberry
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>

// Qmitk
#include "QmitkDwiSoftwarePhantomView.h"

// MITK
#include <mitkImage.h>
#include <mitkDiffusionImage.h>
#include <mitkImageToItk.h>
#include <itkDwiPhantomGenerationFilter.h>
#include <mitkImageCast.h>
#include <mitkProperties.h>

const std::string QmitkDwiSoftwarePhantomView::VIEW_ID = "org.mitk.views.dwisoftwarephantomview";

QmitkDwiSoftwarePhantomView::QmitkDwiSoftwarePhantomView()
    : QmitkFunctionality()
    , m_Controls( 0 )
    , m_MultiWidget( NULL )
{

}

// Destructor
QmitkDwiSoftwarePhantomView::~QmitkDwiSoftwarePhantomView()
{

}

void QmitkDwiSoftwarePhantomView::CreateQtPartControl( QWidget *parent )
{
    // build up qt view, unless already done
    if ( !m_Controls )
    {
        // create GUI widgets from the Qt Designer's .ui file
        m_Controls = new Ui::QmitkDwiSoftwarePhantomViewControls;
        m_Controls->setupUi( parent );
        m_Controls->m_SignalRegionBox->setVisible(false);

        connect((QObject*) m_Controls->m_GeneratePhantomButton, SIGNAL(clicked()), (QObject*) this, SLOT(GeneratePhantom()));
    }
}

template<int ndirs>
std::vector<itk::Vector<double,3> > QmitkDwiSoftwarePhantomView::MakeGradientList()
{
    std::vector<itk::Vector<double,3> > retval;
    vnl_matrix_fixed<double, 3, ndirs>* U =
            itk::PointShell<ndirs, vnl_matrix_fixed<double, 3, ndirs> >::DistributePointShell();

    // Add 0 vector for B0
    int numB0 = ndirs/10;
    if (numB0==0)
        numB0=1;
    itk::Vector<double,3> v;
    v.Fill(0.0);
    for (int i=0; i<numB0; i++)
    {
        retval.push_back(v);
    }

    for(int i=0; i<ndirs;i++)
    {
        itk::Vector<double,3> v;
        v[0] = U->get(0,i); v[1] = U->get(1,i); v[2] = U->get(2,i);
        retval.push_back(v);
    }

    return retval;
}

void QmitkDwiSoftwarePhantomView::GeneratePhantom()
{
    typedef itk::DwiPhantomGenerationFilter< short > FilterType;
    FilterType::GradientListType gradientList;

    m_SignalRegions.clear();
    for (int i=0; i<m_SignalRegionNodes.size(); i++)
    {
        mitk::Image::Pointer mitkBinaryImg = dynamic_cast<mitk::Image*>(m_SignalRegionNodes.at(i)->GetData());
        ItkUcharImgType::Pointer signalRegion = ItkUcharImgType::New();
        mitk::CastToItkImage<ItkUcharImgType>(mitkBinaryImg, signalRegion);
        m_SignalRegions.push_back(signalRegion);
    }

    switch(m_Controls->m_TensorsToDWINumDirsSelect->currentIndex())
    {
    case 0:
        gradientList = MakeGradientList<12>();
        break;
    case 1:
        gradientList = MakeGradientList<42>();
        break;
    case 2:
        gradientList = MakeGradientList<92>();
        break;
    case 3:
        gradientList = MakeGradientList<162>();
        break;
    case 4:
        gradientList = MakeGradientList<252>();
        break;
    case 5:
        gradientList = MakeGradientList<362>();
        break;
    case 6:
        gradientList = MakeGradientList<492>();
        break;
    case 7:
        gradientList = MakeGradientList<642>();
        break;
    case 8:
        gradientList = MakeGradientList<812>();
        break;
    case 9:
        gradientList = MakeGradientList<1002>();
        break;
    default:
        gradientList = MakeGradientList<92>();
    }
    double bVal = m_Controls->m_TensorsToDWIBValueEdit->value();
    itk::ImageRegion<3> imageRegion;
    imageRegion.SetSize(0, m_Controls->m_SizeX->value());
    imageRegion.SetSize(1, m_Controls->m_SizeY->value());
    imageRegion.SetSize(2, m_Controls->m_SizeZ->value());
    mitk::Vector3D spacing;
    spacing[0] = m_Controls->m_SpacingX->value();
    spacing[1] = m_Controls->m_SpacingY->value();
    spacing[2] = m_Controls->m_SpacingZ->value();

    FilterType::Pointer filter = FilterType::New();
    filter->SetGradientList(gradientList);
    filter->SetBValue(bVal);
    filter->SetSNR(m_Controls->m_NoiseLevel->value());
    filter->SetSignalScale(m_Controls->m_SignalScale->value());
    filter->SetImageRegion(imageRegion);
    filter->SetSpacing(spacing);
    filter->SetSignalRegions(m_SignalRegions);
    filter->SetGreyMatterAdc(m_Controls->m_GmAdc->value());

    std::vector< float >                            tensorFA;
    std::vector< float >                            tensorADC;
    std::vector< float >                            tensorWeight;
    std::vector< vnl_vector_fixed<double, 3> >      tensorDirection;
    for (int i=0; i<m_SpinFa.size(); i++)
    {
        tensorFA.push_back(m_SpinFa.at(i)->value());
        tensorADC.push_back(m_SpinAdc.at(i)->value());
        vnl_vector_fixed<double, 3> dir;
        dir[0] = m_SpinX.at(i)->value();
        dir[1] = m_SpinY.at(i)->value();
        dir[2] = m_SpinZ.at(i)->value();
        dir.normalize();
        tensorDirection.push_back(dir);
        tensorWeight.push_back(m_SpinWeight.at(i)->value());
    }
    filter->SetTensorFA(tensorFA);
    filter->SetTensorADC(tensorADC);
    filter->SetTensorWeight(tensorWeight);
    filter->SetTensorDirection(tensorDirection);
    filter->Update();

    mitk::DiffusionImage<short>::Pointer image = mitk::DiffusionImage<short>::New();
    image->SetVectorImage( filter->GetOutput() );
    image->SetB_Value(bVal);
    image->SetDirections(gradientList);
    image->InitializeFromVectorImage();
    mitk::DataNode::Pointer node = mitk::DataNode::New();
    node->SetData( image );
    node->SetName(m_Controls->m_ImageName->text().toStdString());
    GetDataStorage()->Add(node);

    if (m_Controls->m_OutputNumDirectionsBox->isChecked())
    {
        ItkUcharImgType::Pointer numDirImage = filter->GetNumDirectionsImage();
        mitk::Image::Pointer image2 = mitk::Image::New();
        image2->InitializeByItk( numDirImage.GetPointer() );
        image2->SetVolume( numDirImage->GetBufferPointer() );
        mitk::DataNode::Pointer node2 = mitk::DataNode::New();
        node2->SetData(image2);
        QString name(m_Controls->m_ImageName->text());
        name += "_NumDirections";
        node2->SetName(name.toStdString().c_str());
        GetDataStorage()->Add(node2);
    }

    if (m_SignalRegionNodes.size()==0)
        return;

    if (m_Controls->m_OutputDirectionImagesBox->isChecked())
    {
        typedef FilterType::ItkDirectionImageContainer ItkDirectionImageContainer;
        ItkDirectionImageContainer::Pointer container = filter->GetDirectionImageContainer();
        for (int i=0; i<container->Size(); i++)
        {
            FilterType::ItkDirectionImage::Pointer itkImg = container->GetElement(i);
            mitk::Image::Pointer img = mitk::Image::New();
            img->InitializeByItk( itkImg.GetPointer() );
            img->SetVolume( itkImg->GetBufferPointer() );
            mitk::DataNode::Pointer node = mitk::DataNode::New();
            node->SetData(img);
            QString name(m_Controls->m_ImageName->text());
            name += "_Direction";
            name += QString::number(i+1);
            node->SetName(name.toStdString().c_str());
            GetDataStorage()->Add(node);
        }
    }

    if (m_Controls->m_OutputVectorFieldBox->isChecked())
    {
        mitk::Geometry3D::Pointer geometry = image->GetGeometry();
        mitk::Vector3D outImageSpacing = geometry->GetSpacing();
        float minSpacing = 1;
        if(outImageSpacing[0]<outImageSpacing[1] && outImageSpacing[0]<outImageSpacing[2])
            minSpacing = outImageSpacing[0];
        else if (outImageSpacing[1] < outImageSpacing[2])
            minSpacing = outImageSpacing[1];
        else
            minSpacing = outImageSpacing[2];

        mitk::FiberBundleX::Pointer directions = filter->GetOutputFiberBundle();
        directions->SetGeometry(geometry);
        mitk::DataNode::Pointer node = mitk::DataNode::New();
        node->SetData(directions);
        QString name(m_Controls->m_ImageName->text());
        name += "_VectorField";
        node->SetName(name.toStdString().c_str());
        node->SetProperty("Fiber2DSliceThickness", mitk::FloatProperty::New(minSpacing));
        node->SetProperty("Fiber2DfadeEFX", mitk::BoolProperty::New(false));
        GetDataStorage()->Add(node);
    }
}

void QmitkDwiSoftwarePhantomView::UpdateGui()
{
    if (!m_SignalRegionNodes.empty())
    {
        m_Controls->m_SignalRegionBox->setVisible(true);
        m_Controls->m_Instruction->setVisible(false);
    }
    else
    {
        m_Controls->m_SignalRegionBox->setVisible(false);
        m_Controls->m_Instruction->setVisible(true);
    }

    QLayout* layout = m_Controls->m_SignalRegionBox->layout();

    for (int i=0; i<m_Labels.size(); i++)
    {
        delete m_Labels.at(i);
    }
    for (int i=0; i<m_SpinFa.size(); i++)
    {
        delete m_SpinFa.at(i);
        delete m_SpinAdc.at(i);
        delete m_SpinX.at(i);
        delete m_SpinY.at(i);
        delete m_SpinZ.at(i);
        delete m_SpinWeight.at(i);
    }
    m_Labels.clear();
    m_SpinFa.clear();
    m_SpinAdc.clear();
    m_SpinX.clear();
    m_SpinY.clear();
    m_SpinZ.clear();
    m_SpinWeight.clear();

    if (layout)
        delete layout;

    QGridLayout* newlayout = new QGridLayout();

    m_Controls->m_SignalRegionBox->setLayout(newlayout);

    if (!m_SignalRegionNodes.empty())
    {
        QLabel* label1 = new QLabel("Image");
        newlayout->addWidget(label1,0,0);
        m_Labels.push_back(label1);
        QLabel* label2 = new QLabel("FA");
        newlayout->addWidget(label2,0,1);
        m_Labels.push_back(label2);
        QLabel* label3 = new QLabel("ADC");
        newlayout->addWidget(label3,0,2);
        m_Labels.push_back(label3);
        QLabel* label4 = new QLabel("X");
        newlayout->addWidget(label4,0,03);
        m_Labels.push_back(label4);
        QLabel* label5 = new QLabel("Y");
        newlayout->addWidget(label5,0,4);
        m_Labels.push_back(label5);
        QLabel* label6 = new QLabel("Z");
        newlayout->addWidget(label6,0,5);
        m_Labels.push_back(label6);
        QLabel* label7 = new QLabel("Weight");
        newlayout->addWidget(label7,0,6);
        m_Labels.push_back(label7);
    }
    for (int i=0; i<m_SignalRegionNodes.size(); i++)
    {
        QLabel* label = new QLabel(m_SignalRegionNodes.at(i)->GetName().c_str());
        newlayout->addWidget(label,i+1,0);
        m_Labels.push_back(label);

        QDoubleSpinBox* spinFa = new QDoubleSpinBox();
        spinFa->setValue(0.7);
        spinFa->setMinimum(0);
        spinFa->setMaximum(1);
        spinFa->setSingleStep(0.1);
        newlayout->addWidget(spinFa,i+1,1);
        m_SpinFa.push_back(spinFa);

        QDoubleSpinBox* spinAdc = new QDoubleSpinBox();
        newlayout->addWidget(spinAdc,i+1,2);
        spinAdc->setMinimum(0);
        spinAdc->setMaximum(1);
        spinAdc->setSingleStep(0.001);
        spinAdc->setDecimals(3);
        spinAdc->setValue(0.001); ///// ???????????????????????????
        m_SpinAdc.push_back(spinAdc);

        QDoubleSpinBox* spinX = new QDoubleSpinBox();
        newlayout->addWidget(spinX,i+1,3);
        spinX->setValue(1);
        spinX->setMinimum(-1);
        spinX->setMaximum(1);
        spinX->setSingleStep(0.1);
        m_SpinX.push_back(spinX);

        QDoubleSpinBox* spinY = new QDoubleSpinBox();
        newlayout->addWidget(spinY,i+1,4);
        spinY->setMinimum(-1);
        spinY->setMaximum(1);
        spinY->setSingleStep(0.1);
        m_SpinY.push_back(spinY);

        QDoubleSpinBox* spinZ = new QDoubleSpinBox();
        newlayout->addWidget(spinZ,i+1,5);
        spinZ->setMinimum(-1);
        spinZ->setMaximum(1);
        spinZ->setSingleStep(0.1);
        m_SpinZ.push_back(spinZ);

        QDoubleSpinBox* spinWeight = new QDoubleSpinBox();
        newlayout->addWidget(spinWeight,i+1,6);
        spinWeight->setMinimum(0);
        spinWeight->setMaximum(1);
        spinWeight->setSingleStep(0.1);
        spinWeight->setValue(1.0);
        m_SpinWeight.push_back(spinWeight);
    }
}

void QmitkDwiSoftwarePhantomView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
{
    m_MultiWidget = &stdMultiWidget;
}

void QmitkDwiSoftwarePhantomView::StdMultiWidgetNotAvailable()
{
    m_MultiWidget = NULL;
}

void QmitkDwiSoftwarePhantomView::OnSelectionChanged( std::vector<mitk::DataNode*> nodes )
{
    if ( !this->IsVisible() )
    {
        // do nothing if nobody wants to see me :-(
        return;
    }

    m_SignalRegionNodes.clear();

    // iterate all selected objects, adjust warning visibility
    for( std::vector<mitk::DataNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it )
    {
        mitk::DataNode::Pointer node = *it;

        if( node.IsNotNull() && dynamic_cast<mitk::Image*>(node->GetData()) )
        {
            bool isBinary = false;
            node->GetPropertyValue<bool>("binary", isBinary);
            if (isBinary)
                m_SignalRegionNodes.push_back(node);
        }
    }
    UpdateGui();
}
<|endoftext|>