raptr_dflo 48 Posting Pro

Everything actually looks OK, except that following your use of sort->unique->erase, there's still potentially a single -1 in your convex array (if there were any points not on the convex hull), and while you skip it for i, you include it for j when i is at the end of your list. Perhaps a better option than sort->unique->erase is simply:

convex.remove(-1)

Also, if it isn't already assumed, your points must be specified in counter-clockwise order, and there can be no loops in the order of the resulting convex-hull vertices. (Loops in the polygon are OK as long as their points are eliminated from the convex hull. Mostly.)

While your solution for eliminating points looks like it should work fine, it's grossly inefficient. Imagine if you had 1,000 points: you'd be calling is_internal() on the order of a trillion times! So first of all, once P[l] is eliminated from the convex hull, it doesn't need to be checked again:

...
for(int l = 0; l < pts; l++) {
    if(l != i && l != j && l != k && convex[l] != -1) {
        if(is_internal(P[i], P[j], P[k], P[l])) {
            convex[l] = -1;
        }
    }
}
...

Also, since you brute-force iterate over all of the points with i, j and k, you end up checking each triangle 6 times! (e.g., 012, 021, 102, 120, 201, 210.) Since each triangle is uniquely identified by ordering its point-indices, you only need to check larger values from the ones you …

raptr_dflo 48 Posting Pro

Also, in case it helps, I can minimally have one QMainWindow kick off instances of the other, with or without explicitly deleting the second:

import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import SIGNAL


class Main1(QtGui.QMainWindow):
  def __init__(self, parent=None):
    QtGui.QMainWindow.__init__(self, parent)
    self.button = QtGui.QPushButton('Create other window', self)
    self.other_window = None
    self.connect(self.button, SIGNAL('clicked()'), self.spawnMain2)
    self.connect(self, SIGNAL('main2closed()'), self.clearMain2)

  def spawnMain2(self):
    self.other_window = Main2()
    self.connect(self.other_window, SIGNAL('closed()'), self.main2Closed)
    self.other_window.show()

  def main2Closed(self):
    self.emit(SIGNAL('main2closed()'))

  def clearMain2(self):
    del self.other_window
    self.other_window = None


class Main2(QtGui.QMainWindow):
  def __init__(self, parent=None):
    QtGui.QMainWindow.__init__(self, parent)
    self.button = QtGui.QPushButton('Quit', self)
    self.connect(self.button, SIGNAL('clicked()'), self.close)


if __name__ == '__main__':
  app = QtGui.QApplication(sys.argv)
  win = Main1()
  win.show()
  sys.exit(app.exec_())
raptr_dflo 48 Posting Pro

Ah, OK. Then it sounds like something in the CustomWindow is referencing something it shouldn't be, so that when it gets garbage collected, it's causing problems. Possibly a circular reference, such as having it and the MainWindow each setting the other as its 'parent' widget, or it and the MainWindow both referencing the same third widget, so that when one is destroyed (taking its children with it), the other then crashes the interpreter when it tries to destroy the shared child. These are just guesses ... without having the entire source of both classes, it's hard to tell.

raptr_dflo 48 Posting Pro

linuxoidoz,
since i haven't seen this come up yet, if you don't want to destroy and create your dialog each time, have you considered using hide() rather than close(), especially if it's not a modal dialog?
also, i noticed both of your classes are subclassed from QMainWindow ... i haven't tried that myself, maybe CustomWindow should be subclassed from QDialog instead?