Wednesday, January 18, 2017

What file formats are used with 3D printers

3D printing became really popular recently. That's why we should be able to work with various digital models representing real world. Multiple file formats are used for these digital 3D models.

STL format is very common since most CAD programs use it while generating files. It seems all 3D printers accept this format without any adjustments. Files can be ASCII or binary (large files are almost all binary), format is open and well known, see its description in wiki, for example. But this format has its own drawbacks, among them - very poor support of colors.

VRML is a little bit newer and also universal format. It is basically plain text which is good to compress. Designed initially for virtual worlds, it can contain colors, animations, sounds, etc. So it is more advanced comparing to STL.

AMF format is open (defined by ISO standard) and XML based. As it is clear from its name, it was designed for additive manufacturing processes. While STL file is basically a list of vertices only, AMF file has support for colors, materials, etc.

OBJ is a common 3D graphics open format. It is relatively simple format based on vertices (their positions, normals, etc.). OBJ files usually go together with material description files - MTL, containing additional information about materials. OBJ format allows to include information about colors for each vertex.

X3G is a binary format containing exact instructions how to print. It is used by Makerbot devices such as Makerbot Replicator. If you've got file like STL, you can convert it to X3G.

PLY is a format designed for storing data from 3D scanners. It has both ASCII and binary versions.

FBX is a proprietary Autodesk format. It is used for exchanging data between Autodesk programs mainly. Autodesk provides its SDK. Also some unofficial description of format is available. FBX files can be either binary or ASCII.

Wednesday, November 16, 2016

New print option for QtWebEngine in Qt 5.8

Beta version of Qt 5.8 version is out now and list of new features is available here .

For QWebEnginePage a new print option was added. As soon as in Qt 5.7 printing to PDF was already available, now printing through QPrinter also works:

void print(QPrinter *printer, 
       FunctorOrLambda resultCallback);

This is actually implemented by saving web content into temporary PDF file and then printing it out. When saving PDF file, settings of QPrinter are applied.

We can easily find an example of this function usage in demobrowser (Qt installation, Examples folder). resultCallback takes boolean as parameter which indicates whether printing is successful or not.

m_currentPrinter = new QPrinter();
QScopedPointer dialog(new QPrintDialog(m_currentPrinter, this));
dialog->setWindowTitle(tr("Print Document"));
if (dialog->exec() != QDialog::Accepted) {
    slotHandlePagePrinted(false);
    return;
}
page->print(m_currentPrinter, invoke(this, &BrowserMainWindow::slotHandlePagePrinted));
void BrowserMainWindow::slotHandlePagePrinted(bool result)
{
    Q_UNUSED(result);

    delete m_currentPrinter;
    m_currentPrinter = nullptr;
}

Tuesday, May 31, 2016

New method QHostAddress::isMulticast() in Qt 5.6

Among new features of Qt 5.6 new method was added for QHostAddress:

QHostAddress::isMulticast

This bool method returns true if IPv4 or IPv6 address is multicast.

From wikipedia a multicast address is a logical identifier for a group of hosts in a network available to process datagrams or frames intended to be multicast for a network service.

Here is the test program which shows the output for different IPv4 addresses:

#include <QCoreApplication> 
#include <QDebug>
#include <QHostAddress>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QHostAddress ipv4false("127.0.0.1");
    qDebug() << ipv4false.isMulticast(); // false
    // The All Hosts multicast group addresses all 
    // hosts on the same network segment.
    
    QHostAddress ipv4true("224.0.0.1");
    qDebug() << ipv4true.isMulticast(); // true

    return a.exec();
}

It works the same way for IPv6 addresses.

Tuesday, May 24, 2016

QtWebEngine: Printing to PDF

Among new features in Qt 5.7 for QtWebEngine there is printing to PDF. There are several samples which are available for QtWebEngine you can start from this folder in your Qt installation:

c:\Qt\Qt5.7.0\Examples\Qt-5.7\qtwebengine\webenginewidgets\

We will look at demobrowser sample. Let's start from BrowserMainWindow::slotFilePrintToPDF(). Unfortunately Qt still has problem with QPrintDialog not working on Windows described here:

https://bugreports.qt.io/browse/QTBUG-28822
http://www.qtcentre.org/threads/56992-Printer-problem

So for sample purposes we will remove QPrintDialog and just hardcode filename:

void BrowserMainWindow::slotFilePrintToPDF()
{    
#ifndef QT_NO_PRINTER
    if (!currentTab())
        return;    

    QPrinter printer;
    printer.setOutputFileName("test.pdf");
    if (printer.outputFileName().isEmpty() || 
        !m_printerOutputFileName.isEmpty())
        return;
    m_printerOutputFileName = printer.outputFileName();
    currentTab()->page()->printToPdf(printer.pageLayout(), 
                                     invoke(this, &BrowserMainWindow::slotHandlePdfPrinted));
#endif // QT_NO_PRINTER
}

void BrowserMainWindow::slotHandlePdfPrinted(const QByteArray& result)
{
    if (!result.size())
        return;

    QFile file(m_printerOutputFileName);
    m_printerOutputFileName.clear();
    if (!file.open(QFile::WriteOnly))
        return;
    file.write(result.data(), result.size());
    file.close();
} 

So what was actually added in Qt 5.7?

Two overloads of printToPdf() function for QWebEnginePage are here.

They allow to render page content into a PDF document.

Monday, May 16, 2016

QDir::listSeparator

In Qt 5.6 there is a new feature in Qt Core: QDir::listSeparator

    QChar QDir::listSeparator

It returns ';' on Windows and ':' on Unix systems, this is native path list separator, i.e symbol which separates paths in a list.

The aim of introducing this QDir::listSeparator is to replace possible ifdefs in your code and maintain good-looking code on various platforms.

Thursday, February 18, 2016

Google is closing Picasa

On February 12, 2016 Google announced that it is closing Picasa from March 15, 2016. Picasa Web Albums will be closed from May 1, 2016.

Here Google says that:

> The API will still support other functions, including reading photos, reading albums, reading photos in albums, and uploading new photos. Although these operations will continue to be supported and the protocol will remain the same, the content included in the responses and the operation behavior may change. We'll update the documentation on this site with specifics on the changes in March.

Picasa Web Albums will be replaced by Google Photos, a photo and video sharing service of Google.

Since we are using Picasa Web Albums in our free product Wallpaper Updater, we announce we will still support Picasa as long as Google will support reading albums and photos from albums.

Next versions of Wallpaper Updater will also support Google Photos and Flickr. If you have any suggestions or questions about Wallpaper Updater functionality, please share them here.


Saturday, February 6, 2016

Debugging of NUnit tests in Visual Studio

If you using NUnit 2.6 version, you may have a problem with debugging your tests in Visual Studio in case your target framework is .NET Framework 4.0 or 4.5. Here is the simple way to solve this problem.

In NUnit 2.6.x\bin\ folder there is a file nunit.exe.config. It has the following structure:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!--
   The GUI only runs under .NET 2.0 or higher. The
   useLegacyV2RuntimeActivationPolicy setting only
   applies under .NET 4.0 and permits use of mixed
   mode assemblies, which would otherwise not load
   correctly.
  -->
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    </startup>
    <runtime>
        <!-- Ensure that test exceptions don't crash NUnit -->
        <legacyUnhandledExceptionPolicy enabled="1"/>
        <!-- Run partial trust V2 assemblies in full trust under .NET 4.0 -->
        <loadFromRemoteSources enabled="true"/>
        <!-- Look for addins in the addins directory for now -->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="lib;addins"/>
        </assemblyBinding>
    </runtime>
</configuration>
To enable debugging of tests for .NET Framework 4.0 and 4.5 you need to modify this config file (admin privileges are required for that since it is in Program Files):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!--
   The GUI only runs under .NET 2.0 or higher. The
   useLegacyV2RuntimeActivationPolicy setting only
   applies under .NET 4.0 and permits use of mixed
   mode assemblies, which would otherwise not load
   correctly.
  -->
    <startup useLegacyV2RuntimeActivationPolicy="true">       
        <supportedRuntime version="v4.0.30319" />
    </startup>
    <runtime>
        <!-- Ensure that test exceptions don't crash NUnit -->
        <legacyUnhandledExceptionPolicy enabled="1"/>
        <!-- Run partial trust V2 assemblies in full trust under .NET 4.0 -->
        <loadFromRemoteSources enabled="true"/>
        <!-- Look for addins in the addins directory for now -->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="lib;addins"/>
        </assemblyBinding>
    </runtime>
</configuration> 
That's all, after this modification you will be able to debug the tests in Visual Studio.