enter image description here
I used vtkPOpenFOAMReader to read *.foam.
And also I used vtkImagePlaneWidget to read dicom data to 3D show.
Everything is okay, I got the result. But there is a critical issue.
I can see foam data is perfect.
But if add only this code<(1)>, a broken line appears on foam data.
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
using namespace std;
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkImagePlaneWidget> planeWidget = vtkSmartPointer<vtkImagePlaneWidget>::New();/*(1)*/
vtkSmartPointer<vtkPOpenFOAMReader>openFOAMReader = vtkSmartPointer<vtkPOpenFOAMReader>::New();
openFOAMReader->SetCaseType(0);
openFOAMReader->SetFileName("./PatientA/ffr.foam");
openFOAMReader->CreateCellToPointOn();
openFOAMReader->EnableAllCellArrays();
openFOAMReader->DecomposePolyhedraOn();
openFOAMReader->Update();
vtkSmartPointer< vtkGeometryFilter> filter = vtkSmartPointer<vtkGeometryFilter>::New();
filter->SetInputConnection(openFOAMReader->GetOutputPort());
vtkSmartPointer<vtkCompositePolyDataMapper2> mapper = vtkSmartPointer<vtkCompositePolyDataMapper2>::New();
mapper->SetInputConnection(filter->GetOutputPort());
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("p");
mapper->SetScalarRange(-10, 50);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
renWin->Render();
iren->Start();
return true;
}
So why it is happened? It's a very critical issue for me.
Related
With the following code:
#include <QApplication>
#include <QWebEngineView>
#include <QWebEngineProfile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebEngineView w;
QObject::connect(w.page(), &QWebEnginePage::featurePermissionRequested, [&](const QUrl &securityOrigin, QWebEnginePage::Feature feature)
{
w.page()->setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
});
w.setUrl(QUrl("https://mycurrentlocation.net/"));
w.show();
return a.exec();
}
and a USB dongle connected to my 64bit Archlinux system (with geoclue2 installed and working), I don't get the correct geolocation coordinates (which I get on the same website with Google Chrome).
There are both in France but 200km apart.
Update 1:
A similar issue with the same coordinates seems to appear when centering on my position with a QML Map componenent.
Do I need to setup something in order for it to work ?
The issue is not Qt related.
/usr/lib/geoclue-2.0/demos/where-am-i
returns wrong coordinates.
I want to draw a semi-transparent textured sphere in Qt 3D (to plot some kind of colormap on it).
I'm trying to draw a sphere and add a texture. The texture fits good on some regions of the sphere, but on the poligons near its poles it becomes sizzled.
Can you tell me, what's my mistake?
Here's my code that tries to draw a sphere:
#include <QApplication>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DCore/QEntity>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DExtras/QTextureMaterial>
#include <Qt3DExtras/QOrbitCameraController>
#include <Qt3DRender/QTexture>
#include <QPhongAlphaMaterial>
#include <qt3dwindow.h>
#include <QtWidgets/QWidget>
#include <qcamera.h>
#include <qforwardrenderer.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Qt3DExtras::Qt3DWindow* m_view = new Qt3DExtras::Qt3DWindow();
QWidget* container = QWidget::createWindowContainer(m_view);
container->show();
Qt3DCore::QEntity* m_rootEntity = new Qt3DCore::QEntity();
m_view->setRootEntity(m_rootEntity);
m_view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
// let's make a sphere
Qt3DCore::QEntity* m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
Qt3DExtras::QSphereMesh* m_sphereMesh = new Qt3DExtras::QSphereMesh();
m_sphereMesh->setRadius(12.);
m_sphereEntity->addComponent(m_sphereMesh);
// and glue some texture onto our sphere
Qt3DRender::QTextureLoader *loader = new Qt3DRender::QTextureLoader(m_sphereEntity);
Qt3DExtras::QTextureMaterial *material = new Qt3DExtras::QTextureMaterial(m_sphereEntity);
loader->setSource(QUrl::fromLocalFile(a.applicationDirPath() + QStringLiteral("/temp1.png")));
material->setTexture(loader);
m_sphereEntity->addComponent(material);
// initialise camera
Qt3DRender::QCamera *camera = m_view->camera();
camera->lens()->setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0);
camera->setPosition(QVector3D(0.0, 0.0, 40.0));
camera->setViewCenter(QVector3D(0.0, 0.0, 0.0));
// For camera controls.
Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(m_rootEntity);
camController->setLinearSpeed(50.0);
camController->setLookSpeed(180.0);
camController->setCamera(camera);
return a.exec();
}
Here's the temp1.png (the texture of colormap):
And here's the screenshot of my badly textured sphere:
P.S. Also, can you tell me, is there a way to add an alpha channel to my textured material of Qt 3D? It can be extremely useful for me.
I'm making a simple Qt app that reads stuff from a CSV file and generates a PCAP data file out of it for reading by some other software.
And so soon as I invoque pcap_open_dead, pcap_dump_open or pcap_dump, I get no more console output upon running my small converter. Even the Hello World that comes at the beginning of the main doesn't show up any more. From the code below, if I simply comment out those three methods, the console output and "Hello World" come back.
Being new and therefore clueless about pcap, I ask for help.
#include <QCoreApplication>
#include <iostream>
#include "pcap.h"
using namespace std;
struct pcapWriter_S
{
bool isAvailable;
int m_OutPcapIpId;
pcap_t* m_OutPcapHandle;
pcap_dumper_t* m_OutPcapFile;
}m_pcapWriter;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout << "Hello World!" << endl;
//m_pcapWriter.m_OutPcapHandle = pcap_open_dead(DLT_EN10MB,65535);
//m_pcapWriter.m_OutPcapFile = pcap_dump_open(m_pcapWriter.m_OutPcapHandle, QString("tmp_csv_out.pcap").toAscii().data());
m_pcapWriter.m_OutPcapIpId = 1;
if (m_pcapWriter.m_OutPcapFile != 0)
{
m_pcapWriter.isAvailable = true;
}
QByteArray pkt_data;
// Omitted code to generate pkt data from input file
m_pcapWriter.m_OutPcapIpId++;
//pcap_dump((unsigned char*)m_pcapWriter.m_OutPcapFile, &header, (unsigned char*)pkt_data.data());
return a.exec();
}
Somehow this was due to me calling pcap_open but not pcap_close quite yet. In between console stuff gets lost - can't swear it gets written on the pcap thing but it blocks the console anyway.
I have some troubles translating my application from Russian to English using QTranslator. That is a way i tried to do it:
1) my .pro file contains the following strings:
CODECFORTR = UTF-8
CODECFORSRC = UTF-8
TRANSLATIONS += app_en.ts
2) that is my main.cpp file:
#include <QLabel>
#include <QTranslator>
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QTranslator translator;
bool ok = translator.load(":/app_en.qm");
ok = app.installTranslator(&translator);
QLabel label(QObject::tr("Some text in Russian"));
label.show();
return app.exec();
}
3) I have used lupdate to generate .ts file, than linguist to generate.qm file. But when I run my application russian text stays on Russian.
4) I also tried to swap languages - use English as source and than translate it to Russian using the same steps - everything works ok and I got correct translation. It seems that I didn't specify something to make Qt know i need to translate Russian (which is a native language for my system) to Englih. Can anyone help?
I'm trying to write a program that would use 7-Zip DLL for reading files from inside archive files (7z, zip etc).
Here's where I'm so far:
#include <QtCore/QCoreApplication>
#include <QLibrary>
#include <QUuid>
#include <iostream>
using namespace std;
#include "7z910/CPP/7zip/Archive/IArchive.h"
#include "7z910/CPP/7zip/IStream.h"
#include "MyCom.h"
// {23170F69-40C1-278A-1000-000110070000}
QUuid CLSID_CFormat7z(0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
typedef int (*CreateObjectFunc)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
void readFileInArchive()
{
QLibrary myLib("7z.dll");
CreateObjectFunc myFunction = (CreateObjectFunc)myLib.resolve("CreateObject");
if (myFunction == 0) {
cout << "CreateObject resolve failed!";
return;
}
else {
cout << "CreateObject resolved";
}
CMyComPtr<IOutArchive> outArchive;
myFunction(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
readFileInArchive();
return a.exec();
}
Trying to build that in Qt Creator will lead to following error:
cannot convert 'QUuid*' to 'const GUID*' in argument passing
How should QUuid be correctly used in this context?
Also, being a C++ and Qt newbie I haven't yet quite grasped templates or interfaces, so overall I'm having trouble getting through these first steps. If someone could give tips or even example code on how for example an image file could be extracted from ZIP file (to be shown in Qt GUI later on*), I would highly appreciate that.
My main goal at the moment is to write a program with GUI for selecting archive files containing image files (PNG, JPG etc) and displaying those files one at a time in the GUI. A Qt based CDisplayEx in short.
You have to explicitly cast QUuid to GUID:
QUuid boo;
GUID uid = static_cast<GUID>(boo);
You must use some conversion between the 2 types.
Looking at Qt documentation, I found that there is a GUID operator that transform a QUuid to a Windows GUID : http://doc.trolltech.com/4.6/quuid.html#operator-GUID
Of course, this is not cross-plateform.