Results 1 to 5 of 5

Thread: Read data from txt file

  1. #1
    Join Date
    Sep 2012
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Read data from txt file

    Hi Qt Users,


    I have a small question about reading data from txt file and put it into spinbox, editline

    I have txt file like this :

    (Transform "EulerTransform")
    (NumberOfParameters 6)
    (TransformParameters 0.010616 0.024962 -0.006457 -9.413307 10.784872 12.639569)
    (InitialTransformParametersFileName "NoInitialTransform")
    (HowToCombineTransforms "Compose")

    // Image specific
    (FixedImageDimension 3)
    (MovingImageDimension 3)
    (FixedInternalImagePixelType "float")
    (MovingInternalImagePixelType "float")
    (Size 84 99 98)

    (Index 0 0 0)
    (Spacing 2.0000000000 2.0000000000 2.0000000000)
    (Origin -80.0000000000 -33.0000000000 -112.0000000000)
    (Direction 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000)
    (UseDirectionCosines "false")

    // EulerTransform specific
    (CenterOfRotationPoint 3.0000000000 65.0000000000 -15.0000000000)
    (ComputeZYX "false")


    Here : I have already tried to write a method, but I have a problem with parsing data form line () :

    Qt Code:
    1. //------------------------------------------------------------------------------
    2. void vTool::LoadFile()
    3. {
    4. //Open File to read the transformation parameters
    5. QString fileName = QFileDialog::getOpenFileName(
    6. this,
    7. "Choose elastix transfrom parameters file",
    8. vtksys::SystemTools::GetFilenamePath(mCurrentSlicerManager->GetFileName()).c_str(),
    9. "TransformParameters.0.txt");
    10.  
    11. if(fileName != "") {
    12. QFile file(fileName);
    13. if(!file.open(QIODevice::ReadOnly)) {
    14. QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
    15. return;
    16. }
    17.  
    18. // Center of point
    19. QString Xcen, Ycen, Zcen;
    20.  
    21.  
    22. QString Xt_txt, Yt_txt, Zt_txt, Xr_txt, Yr_txt, Zr_txt;
    23.  
    24. double Xtrans = 0, Ytrans = 0, Ztrans = 0;
    25. double Xrot = 0, Yrot = 0, Zrot = 0;
    26.  
    27. QTextStream in(&file);
    28.  
    29. while(!in.atEnd())
    30. {
    31. QString mText = in.readLine();
    32. if(mText.startsWith("(TransformParameters"))
    33. {
    34. // in <<'/0'<< Xr_txt <<'/0' << Yr_txt<< '/0' << Zr_txt << '/0'<< Xt_txt << '/0' << Yt_txt <<'/0'<< Zt_txt;
    35. mText.split(" ");
    36.  
    37. Xrot = Xr_txt.toDouble();
    38. Yrot = Yr_txt.toDouble();
    39. Zrot = Zr_txt.toDouble();
    40.  
    41. xrot_sb->setValue(Xrot);
    42. yrot_sb->setValue(Yrot);
    43. zrot_sb->setValue(Zrot);
    44.  
    45. Xtrans = Xt_txt.toDouble();
    46. Ytrans = Yt_txt.toDouble();
    47. Ztrans = Zt_txt.toDouble();
    48.  
    49. xtrans_sb->setValue(Xtrans);
    50. ytrans_sb->setValue(Ytrans);
    51. ztrans_sb->setValue(Ztrans);
    52.  
    53. }
    54.  
    55. if(mText.startsWith("(CenterOfRotationPoint"))
    56. {
    57.  
    58. in << Xcen << Ycen << Zcen;
    59. Xval->setText(Xcen);
    60. Yval->setText(Ycen);
    61. Zval->setText(Zcen);
    62. }
    63.  
    64.  
    65.  
    66. }
    67.  
    68. }
    69.  
    70. }
    To copy to clipboard, switch view to plain text mode 
    Could You help me please ?

    I would appreciate for any help please
    Last edited by wysota; 10th March 2013 at 12:30. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read data from txt file

    What exactly is the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2012
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read data from txt file

    I want to read transformParameters values from txt file :
    (TransformParameters 0.010616 0.024962 -0.006457 -9.413307 10.784872 12.639569)

    (CenterOfRotationPoint 3.0000000000 65.0000000000 -15.0000000000)
    and put into variables : Xr_txt,Yr_txt, Zr_txt ...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read data from txt file

    Yes, I understand that. But what doesn't work? I don't see any code of yours that tries to read any data from the line.

    By the way, don't you think the file format is simple enough to write a proper parser for it? You can even use tools such as qlalr to help you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2012
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read data from txt file

    Quote Originally Posted by wysota View Post
    Yes, I understand that. But what doesn't work? I don't see any code of yours that tries to read any data from the line.

    By the way, don't you think the file format is simple enough to write a proper parser for it? You can even use tools such as qlalr to help you.


    Ok, thank I have already resolved this problem

    Thanks very much for help.

Similar Threads

  1. Replies: 1
    Last Post: 30th November 2012, 17:54
  2. Replies: 8
    Last Post: 8th May 2012, 09:39
  3. Replies: 5
    Last Post: 10th June 2011, 10:58
  4. Read/write data from file
    By Insomnium in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2010, 07:35
  5. Replies: 3
    Last Post: 23rd June 2006, 17:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.